﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;

public partial class Main_Inventory_StockJournal : System.Web.UI.Page
{
    string USERNAME = "";
    string FINYEAR = "";
    string strsql = "";
    string reqTFOID = "";
    string reqSJRID = "";
    Datautility DU = new Datautility();
    #region Issue Declaration
    int issueCounter = 2;
    List<string> listissuecounter;
    List<string> listddlissueitems;
    List<string> listhidissuesjiid;
    List<string> listhidissuesidid;
    List<string> listtxtissueunit;
    List<string> listhidissueuomid;
    List<string> listtxtissuequantity;
    List<string> listbtnissueqty;
    List<string> listhidissueLocation;
    List<string> listtxtissuerate;
    List<string> listtxtissueamount;

    #endregion Issue Declaration
    #region recieved Declaration
    int recievedCounter = 2;
    List<string> listrecievedcounter;
    List<string> listddlrecieveditems;
    List<string> listhidrecievedsjiid;
    List<string> listhidrecievedsidid;
    List<string> listtxtrecievedunit;
    List<string> listhidrecieveduomid;
    List<string> listtxtrecievedquantity;
    List<string> listbtnrecievedqty;
    List<string> listhidrecievedLocation;
    List<string> listtxtrecievedrate;
    List<string> listtxtrecievedamount;
    #endregion recieved Declaration
    #region transfer Declaration
    int transferCounter = 2;
    List<string> listtransfercounter;
    List<string> listddltransferitems;
    List<string> listhidtransfersjiid;
    List<string> listhidtransfersidid;
    List<string> listtxttransferunit;
    List<string> listhidtransferuomid;
    List<string> listtxttransferquantity;
    List<string> listbtntransferqty;
    List<string> listhidtransferLocation;
    List<string> listtxttransferrate;
    List<string> listtxttransferamount;
    #endregion transfer Declaration
    #region input Declaration
    int inputCounter = 2;
    List<string> listinputcounter;
    List<string> listddlinputitems;
    List<string> listhidinputsjiid;
    List<string> listhidinputsidid;
    List<string> listtxtinputunit;
    List<string> listhidinputuomid;
    List<string> listtxtinputquantity;
    List<string> listbtninputqty;
    List<string> listhidinputLocation;
    List<string> listtxtinputrate;
    List<string> listtxtinputamount;
    #endregion input Declaration
    #region output Declaration
    int outputCounter = 2;
    List<string> listoutputcounter;
    List<string> listddloutputitems;
    List<string> listhidoutputsjiid;
    List<string> listhidoutputsidid;
    List<string> listtxtoutputunit;
    List<string> listhidoutputuomid;
    List<string> listtxtoutputquantity;
    List<string> listbtnoutputqty;
    List<string> listhidoutputLocation;
    List<string> listtxtoutputrate;
    List<string> listtxtoutputamount;
    #endregion output Declaration
    #region production Declaration
    int productionCounter = 2;
    List<string> listproductioncounter;
    List<string> listddlproductionitems;
    List<string> listhidproductionsjiid;
    List<string> listhidproductionsidid;
    List<string> listtxtproductionunit;
    List<string> listhidproductionuomid;
    List<string> listtxtproductionquantity;
    List<string> listbtnproductionqty;
    List<string> listhidproductionLocation;
    List<string> listtxtproductionrate;
    List<string> listtxtproductionamount;
    #endregion production Declaration
    #region physical Declaration
    int physicalCounter = 2;
    List<string> listphysicalcounter;
    List<string> listddlphysicalitems;
    List<string> listhidphysicalsjiid;
    List<string> listhidphysicalsidid;
    List<string> listtxtphysicalunit;
    List<string> listhidphysicaluomid;
    List<string> listtxtphysicalquantity;
    List<string> listbtnphysicalqty;
    List<string> listhidphysicalLocation;
    List<string> listtxtphysicalrate;
    List<string> listtxtphysicalamount;
    List<string> listtxtphysicalreason;
    #endregion physical Declaration
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        overrideissueaddmore("issue");  // 3
        overriderecievedaddmore("recieved");  // 4
        overridetransferaddmore("transfer");  // 5
        overrideinputaddmore("input");   // 1
        overrideoutputaddmore("output"); // 1
        overrideproductionaddmore("production");  // 2
        overridephysicaladdmore("physical");  // 6
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        MaintainScrollPositionOnPostBack = true;
        if (Session["username"] != null && Session["FINYEAR"] != null)
        {
           USERNAME = Session["username"].ToString();
           FINYEAR = Session["FINYEAR"].ToString();
        }
        else
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        if (!IsPostBack)
        {


            BindJounalFormat();

            #region Issue Initialize View State
            listissuecounter = new List<string>();
            ViewState["listissuecounter"] = listissuecounter;

            listddlissueitems = new List<string>();
            ViewState["listddlissueitems"] = listddlissueitems;

            listhidissuesjiid = new List<string>();
            ViewState["listhidissuesjiid"] = listhidissuesjiid;

            listhidissuesidid = new List<string>();
            ViewState["listhidissuesidid"] = listhidissuesidid;

            listtxtissueunit = new List<string>();
            ViewState["listtxtissueunit"] = listtxtissueunit;

            listhidissueuomid = new List<string>();
            ViewState["listhidissueuomid"] = listhidissueuomid;

            listtxtissuequantity = new List<string>();
            ViewState["listtxtissuequantity"] = listtxtissuequantity;

            listbtnissueqty = new List<string>();
            ViewState["listbtnissueqty"] = listbtnissueqty;

            listhidissueLocation = new List<string>();
            ViewState["listhidissueLocation"] = listhidissueLocation;

            listtxtissuerate = new List<string>();
            ViewState["listtxtissuerate"] = listtxtissuerate;

            listtxtissueamount = new List<string>();
            ViewState["listtxtissueamount"] = listtxtissueamount;

            #endregion Issue Initialize

            #region recieved Initialize View State
            listrecievedcounter = new List<string>();
            ViewState["listrecievedcounter"] = listrecievedcounter;

            listddlrecieveditems = new List<string>();
            ViewState["listddlrecieveditems"] = listddlrecieveditems;

            listhidrecievedsjiid = new List<string>();
            ViewState["listhidrecievedsjiid"] = listhidrecievedsjiid;

            listhidrecievedsidid = new List<string>();
            ViewState["listhidrecievedsidid"] = listhidrecievedsidid;

            listtxtrecievedunit = new List<string>();
            ViewState["listtxtrecievedunit"] = listtxtrecievedunit;

            listhidrecieveduomid = new List<string>();
            ViewState["listhidrecieveduomid"] = listhidrecieveduomid;

            listtxtrecievedquantity = new List<string>();
            ViewState["listtxtrecievedquantity"] = listtxtrecievedquantity;

            listbtnrecievedqty = new List<string>();
            ViewState["listbtnrecievedqty"] = listbtnrecievedqty;

            listhidrecievedLocation = new List<string>();
            ViewState["listhidrecievedLocation"] = listhidrecievedLocation;

            listtxtrecievedrate = new List<string>();
            ViewState["listtxtrecievedrate"] = listtxtrecievedrate;

            listtxtrecievedamount = new List<string>();
            ViewState["listtxtrecievedamount"] = listtxtrecievedamount;

            #endregion recieved Initialize

            #region transfer Initialize View State
            listtransfercounter = new List<string>();
            ViewState["listtransfercounter"] = listtransfercounter;

            listddltransferitems = new List<string>();
            ViewState["listddltransferitems"] = listddltransferitems;

            listhidtransfersjiid = new List<string>();
            ViewState["listhidtransfersjiid"] = listhidtransfersjiid;

            listhidtransfersidid = new List<string>();
            ViewState["listhidtransfersidid"] = listhidtransfersidid;

            listtxttransferunit = new List<string>();
            ViewState["listtxttransferunit"] = listtxttransferunit;

            listhidtransferuomid = new List<string>();
            ViewState["listhidtransferuomid"] = listhidtransferuomid;

            listtxttransferquantity = new List<string>();
            ViewState["listtxttransferquantity"] = listtxttransferquantity;

            listbtntransferqty = new List<string>();
            ViewState["listbtntransferqty"] = listbtntransferqty;

            listhidtransferLocation = new List<string>();
            ViewState["listhidtransferLocation"] = listhidtransferLocation;

            listtxttransferrate = new List<string>();
            ViewState["listtxttransferrate"] = listtxttransferrate;

            listtxttransferamount = new List<string>();
            ViewState["listtxttransferamount"] = listtxttransferamount;

            #endregion transfer Initialize

            #region input Initialize View State
            listinputcounter = new List<string>();
            ViewState["listinputcounter"] = listinputcounter;

            listddlinputitems = new List<string>();
            ViewState["listddlinputitems"] = listddlinputitems;

            listhidinputsjiid = new List<string>();
            ViewState["listhidinputsjiid"] = listhidinputsjiid;

            listhidinputsidid = new List<string>();
            ViewState["listhidinputsidid"] = listhidinputsidid;

            listtxtinputunit = new List<string>();
            ViewState["listtxtinputunit"] = listtxtinputunit;

            listhidinputuomid = new List<string>();
            ViewState["listhidinputuomid"] = listhidinputuomid;

            listtxtinputquantity = new List<string>();
            ViewState["listtxtinputquantity"] = listtxtinputquantity;

            listbtninputqty = new List<string>();
            ViewState["listbtninputqty"] = listbtninputqty;

            listhidinputLocation = new List<string>();
            ViewState["listhidinputLocation"] = listhidinputLocation;

            listtxtinputrate = new List<string>();
            ViewState["listtxtinputrate"] = listtxtinputrate;

            listtxtinputamount = new List<string>();
            ViewState["listtxtinputamount"] = listtxtinputamount;

            #endregion input Initialize

            #region output Initialize View State
            listoutputcounter = new List<string>();
            ViewState["listoutputcounter"] = listoutputcounter;

            listddloutputitems = new List<string>();
            ViewState["listddloutputitems"] = listddloutputitems;


            listhidoutputsjiid = new List<string>();
            ViewState["listhidoutputsjiid"] = listhidoutputsjiid;

            listhidoutputsidid = new List<string>();
            ViewState["listhidoutputsidid"] = listhidoutputsidid;

            listtxtoutputunit = new List<string>();
            ViewState["listtxtoutputunit"] = listtxtoutputunit;

            listhidoutputuomid = new List<string>();
            ViewState["listhidoutputuomid"] = listhidoutputuomid;

            listtxtoutputquantity = new List<string>();
            ViewState["listtxtoutputquantity"] = listtxtoutputquantity;

            listbtnoutputqty = new List<string>();
            ViewState["listbtnoutputqty"] = listbtnoutputqty;

            listhidoutputLocation = new List<string>();
            ViewState["listhidoutputLocation"] = listhidoutputLocation;

            listtxtoutputrate = new List<string>();
            ViewState["listtxtoutputrate"] = listtxtoutputrate;

            listtxtoutputamount = new List<string>();
            ViewState["listtxtoutputamount"] = listtxtoutputamount;

            #endregion output Initialize

            #region production Initialize View State
            listproductioncounter = new List<string>();
            ViewState["listproductioncounter"] = listproductioncounter;

            listddlproductionitems = new List<string>();
            ViewState["listddlproductionitems"] = listddlproductionitems;

            listhidproductionsjiid = new List<string>();
            ViewState["listhidproductionsjiid"] = listhidproductionsjiid;

            listhidproductionsidid = new List<string>();
            ViewState["listhidproductionsidid"] = listhidproductionsidid;

            listtxtproductionunit = new List<string>();
            ViewState["listtxtproductionunit"] = listtxtproductionunit;

            listhidproductionuomid = new List<string>();
            ViewState["listhidproductionuomid"] = listhidproductionuomid;

            listtxtproductionquantity = new List<string>();
            ViewState["listtxtproductionquantity"] = listtxtproductionquantity;

            listbtnproductionqty = new List<string>();
            ViewState["listbtnproductionqty"] = listbtnproductionqty;

            listhidproductionLocation = new List<string>();
            ViewState["listhidproductionLocation"] = listhidproductionLocation;

            listtxtproductionrate = new List<string>();
            ViewState["listtxtproductionrate"] = listtxtproductionrate;

            listtxtproductionamount = new List<string>();
            ViewState["listtxtproductionamount"] = listtxtproductionamount;

            #endregion production Initialize

            #region physical Initialize View State
            listphysicalcounter = new List<string>();
            ViewState["listphysicalcounter"] = listphysicalcounter;

            listddlphysicalitems = new List<string>();
            ViewState["listddlphysicalitems"] = listddlphysicalitems;

            listhidphysicalsjiid = new List<string>();
            ViewState["listhidphysicalsjiid"] = listhidphysicalsjiid;

            listhidphysicalsidid = new List<string>();
            ViewState["listhidphysicalsidid"] = listhidphysicalsidid;

            listtxtphysicalunit = new List<string>();
            ViewState["listtxtphysicalunit"] = listtxtphysicalunit;

            listhidphysicaluomid = new List<string>();
            ViewState["listhidphysicaluomid"] = listhidphysicaluomid;

            listtxtphysicalquantity = new List<string>();
            ViewState["listtxtphysicalquantity"] = listtxtphysicalquantity;

            listbtnphysicalqty = new List<string>();
            ViewState["listbtnphysicalqty"] = listbtnphysicalqty;

            listhidphysicalLocation = new List<string>();
            ViewState["listhidphysicalLocation"] = listhidphysicalLocation;

            listtxtphysicalrate = new List<string>();
            ViewState["listtxtphysicalrate"] = listtxtphysicalrate;

            listtxtphysicalamount = new List<string>();
            ViewState["listtxtphysicalamount"] = listtxtphysicalamount;

            listtxtphysicalreason = new List<string>();
            ViewState["listtxtphysicalreason"] = listtxtphysicalreason;

            #endregion physical Initialize

            #region Issue Call Item Funtion
            Issue_binditem(ddlissueitems1);
            Issue_binditem(ddlissueitems2);
            Issue_BindJavaScriptItemQtyPopUp();
            #endregion End Issue Call Item Funtion
            #region recieved Call Item Funtion
            recieved_binditem(ddlrecieveditems1);
            recieved_binditem(ddlrecieveditems2);
            recieved_BindJavaScriptItemQtyPopUp();
            #endregion End recieved Call Item Funtion
            #region transfer Call Item Funtion
            transfer_binditem(ddltransferitems1);
            transfer_binditem(ddltransferitems2);
            transfer_BindJavaScriptItemQtyPopUp();
            transfer_BindLocation();
            #endregion End transfer Call Item Funtion
            #region physical Call Item Funtion
            physical_binditem(ddlphysicalitems1);
            physical_binditem(ddlphysicalitems2);
            physical_BindJavaScriptItemQtyPopUp();
            #endregion End physical Call Item Funtion
            #region production Call Item Funtion
            production_binditem(ddlproductionitems1);
            production_binditem(ddlproductionitems2);
            production_BindJavaScriptItemQtyPopUp();
            #endregion End production Call Item Funtion
            #region input jounal Call Item Funtion
            input_binditem(ddlinputitems1);
            input_binditem(ddlinputitems2);
            input_BindJavaScriptItemQtyPopUp();
            #endregion End input jounal Call Item Funtion
            #region output jounal Call Item Funtion
            output_binditem(ddloutputitems1);
            output_binditem(ddloutputitems2);
            output_BindJavaScriptItemQtyPopUp();
            #endregion End output jounal Call Item Funtion

            if (Request.QueryString["TFOID"] != string.Empty && Request.QueryString["SJRID"] != string.Empty)
            {
                reqTFOID = Request.QueryString["TFOID"].ToString();
                reqSJRID = Request.QueryString["SJRID"].ToString();
                EditBindHead();
                EditBindOtherDetails();
            }
        }
        
        #region Issue Common Each Time Javascript
        Issue_BindJavaScriptItemQtyPopUp();
        #endregion Issue Common Each Time
        #region recieved Common Each Time Javascript
        recieved_BindJavaScriptItemQtyPopUp();
        #endregion End Issue Common Each Time
        #region transfer Common Each Time Javascript
        transfer_BindJavaScriptItemQtyPopUp();
        #endregion End transfer Common Each Time
        #region physical Common Each Time Javascript
        physical_BindJavaScriptItemQtyPopUp();
        #endregion End physical Common Each Time
        #region production Common Each Time Javascript
        prod_BindJavaScriptItemQtyPopUp();
        production_BindJavaScriptItemQtyPopUp();
        #endregion End production Common Each Time
        #region input jounal Common Each Time Javascript
        input_BindJavaScriptItemQtyPopUp();
        #endregion End input jounal Common Each Time
        #region output jounal Common Each Time Javascript
        output_BindJavaScriptItemQtyPopUp();
        #endregion End output jounal Common Each Time

    }
    #region Common Mendatory Function


    protected void EditBindHead()
    {
        SqlParameter[] paraedit = { 
                                   new SqlParameter("TFOID",reqTFOID),
                                   new SqlParameter("SJRID",reqSJRID)
                                  };
        DataTable dthead = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Main_by_tfoid_sjrid", paraedit);
        if (dthead.Rows.Count > 0)
        {
            ddljrnFormate.Enabled = false;

            ddljrnFormate.SelectedValue = dthead.Rows[0]["TFOID"].ToString();
            ddljrnFormate_SelectedIndexChanged(this, EventArgs.Empty);

            txtdate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(dthead.Rows[0]["SJRDATE"].ToString())).Replace("01/01/1900", "");

            ddlfromLoacation.SelectedValue = dthead.Rows[0]["FROM_WHSID"].ToString();
            ddlToLoacation.SelectedValue = dthead.Rows[0]["To_WHSID"].ToString();
        }
        EditLoadAddMoreRowControl();
    }
    protected void EditLoadAddMoreRowControl()
    {
        if (Request.QueryString["category"] != null)
        {
            string Category = "";
            Category = Request.QueryString["Category"].ToString();
            if (Category == "1") // Journal(Input and Output)
            {
                SqlParameter[] parmain = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","issue") // Input
                               };
                DataTable DTADDMOREInput = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmain);
                if (DTADDMOREInput.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREInput.Rows.Count; i++)
                    {
                        input_ADDMORE("input");
                        input_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREInput,"1","input");
                }
                SqlParameter[] parmaout = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","receipt") // output
                               };
                DataTable DTADDMOREOutput = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmaout);
                if (DTADDMOREOutput.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREOutput.Rows.Count; i++)
                    {
                        output_ADDMORE("output");
                        output_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREOutput,"1","output");
                }
            }
            else if (Category == "2")  //  Production 
            {

                ///////////////////// Prod //////////////////////////////
                SqlParameter[] parmaprod = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","receipt") // receipt
                               };
                DataTable DTADDMOREprod = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmaprod);
                if (DTADDMOREprod.Rows.Count > 0)
                {
                    prod_BindJavaScriptItemQtyPopUp();
                    EditBindItems(DTADDMOREprod, "2", "prod");
                }
                ///////////////////// Prod //////////////////////////////

                SqlParameter[] parmapr = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","issue") // receipt
                               };
                DataTable DTADDMOREproduction = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmapr);
                if (DTADDMOREproduction.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREproduction.Rows.Count; i++)
                    {
                        production_ADDMORE("production");
                        production_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREproduction,"2","");
                }
            }
            else if (Category == "3")  //  Issue 
            {
                SqlParameter[] parmaisssue = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","issue") // Issue
                               };
                DataTable DTADDMOREIssue = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmaisssue);
                if (DTADDMOREIssue.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREIssue.Rows.Count; i++)
                    {
                        issue_ADDMORE("issue");
                        Issue_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREIssue,"3","");
                }
            }
            else if (Category == "4")  //  Receipt
            {
                SqlParameter[] parmaRE = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","receipt") // Receipt
                               };
                DataTable DTADDMOREReceipt = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmaRE);
                if (DTADDMOREReceipt.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREReceipt.Rows.Count; i++)
                    {
                        recieved_ADDMORE("recieved");
                        recieved_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREReceipt,"4","");
                }
            }
            else if (Category == "5")  //  Transfer
            {
                SqlParameter[] parmatr = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","issue") // Receipt
                               };
                DataTable DTADDMORETransfer = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmatr);
                if (DTADDMORETransfer.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMORETransfer.Rows.Count; i++)
                    {
                        transfer_ADDMORE("transfer");
                        transfer_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMORETransfer,"5","");
                   
                }
            }
            else if (Category == "6")  //  Physical
            {
                SqlParameter[] parmaphysical = { 
                                new SqlParameter("@SJRID",reqSJRID),
                                new SqlParameter("@issueReceipt","issue") // Receipt
                               };
                DataTable DTADDMOREPhysical = DU.getdatausingprocedure("usp_ivr_get_STKJRNL_Edit_Items", parmaphysical);
                if (DTADDMOREPhysical.Rows.Count > 0)
                {
                    for (int i = 2; i < DTADDMOREPhysical.Rows.Count; i++)
                    {
                        physical_ADDMORE("physical");
                        physical_BindJavaScriptItemQtyPopUp();
                    }
                    EditBindItems(DTADDMOREPhysical,"6","");
                }
            }
        }
    }

    protected void EditBindItems(DataTable dtitems,string Category,string subcategory)
    {
        if (Category == "1" && subcategory=="input") // Journal (Input)
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddlinputitems = (DropDownList)tbl_input.Rows[i].FindControl("ddlinputitems" + i.ToString());
                    HiddenField hidinputsjiid = (HiddenField)tbl_input.Rows[i].FindControl("hidinputsjiid" + i.ToString());
                    HiddenField hidinputuomid = (HiddenField)tbl_input.Rows[i].FindControl("hidinputuomid" + i.ToString());
                    TextBox txtinputquantity = (TextBox)tbl_input.Rows[i].FindControl("txtinputquantity" + i.ToString());
                    TextBox txtinputrate = (TextBox)tbl_input.Rows[i].FindControl("txtinputrate" + i.ToString());
                    TextBox txtinputamount = (TextBox)tbl_input.Rows[i].FindControl("txtinputamount" + i.ToString());
                    HiddenField hidinputLocation = (HiddenField)tbl_input.Rows[i].FindControl("hidinputLocation" + i.ToString());
                    HiddenField hidinputsidid = (HiddenField)tbl_input.Rows[i].FindControl("hidinputsidid" + i.ToString());

                    ddlinputitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    input_ddlitems_OnSelectedIndexChanged(ddlinputitems, EventArgs.Empty);
                    hidinputuomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtinputquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtinputrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtinputamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidinputLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "1", "input");

                    hidinputsjiid.Value = dtitems.Rows[i - 1]["SJIID"].ToString();
                    hidinputsidid.Value = EditDetailedLocation(hidinputsjiid.Value);
                }
            }
        }
        else if (Category == "1" && subcategory=="output") // Journal (Output)
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddloutputitems = (DropDownList)tbl_output.Rows[i].FindControl("ddloutputitems" + i.ToString());
                    HiddenField hidoutputsjiid = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputsjiid" + i.ToString());
                    HiddenField hidoutputuomid = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputuomid" + i.ToString());
                    TextBox txtoutputquantity = (TextBox)tbl_output.Rows[i].FindControl("txtoutputquantity" + i.ToString());
                    TextBox txtoutputrate = (TextBox)tbl_output.Rows[i].FindControl("txtoutputrate" + i.ToString());
                    TextBox txtoutputamount = (TextBox)tbl_output.Rows[i].FindControl("txtoutputamount" + i.ToString());
                    HiddenField hidoutputLocation = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputLocation" + i.ToString());
                    HiddenField hidoutputsidid = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputsidid" + i.ToString());

                    ddloutputitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    output_ddlitems_OnSelectedIndexChanged(ddloutputitems, EventArgs.Empty);
                    hidoutputuomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtoutputquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtoutputrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtoutputamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidoutputLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "1", "output");

                    hidoutputsjiid.Value = dtitems.Rows[i - 1]["SJIID"].ToString();
                    hidoutputsidid.Value = EditDetailedLocation(hidoutputsjiid.Value);
                }
            }
        }
        else if (Category == "2" && subcategory=="prod")
        {
            if (dtitems.Rows.Count > 0)
            {
                //for (int i = 1; i <= dtitems.Rows.Count; i++)
                //{
                    //DropDownList ddlproditem = (DropDownList)tbl_production.Rows[i].FindControl("ddlproditem" + i.ToString());
                    ////HiddenField hidTITID = (HiddenField)tbl_production.Rows[i].FindControl("hidTITID" + i.ToString());
                    //HiddenField hidproduomid = (HiddenField)tbl_production.Rows[i].FindControl("hidproduomid" + i.ToString());
                    //TextBox txtprodquantity = (TextBox)tbl_production.Rows[i].FindControl("txtprodquantity" + i.ToString());
                    //TextBox txtprodrate = (TextBox)tbl_production.Rows[i].FindControl("txtprodrate" + i.ToString());
                    //TextBox txtprodamount = (TextBox)tbl_production.Rows[i].FindControl("txtprodamount" + i.ToString());
                    //HiddenField hidprodLocation = (HiddenField)tbl_production.Rows[i].FindControl("hidprodLocation" + i.ToString());
                    ////HiddenField hidTIDID = (HiddenField)tbl_production.Rows[i].FindControl("hidTIDID" + i.ToString());

                    ddlproditem.SelectedValue = dtitems.Rows[0]["ITMID"].ToString();
                    prod_ddlitems_OnSelectedIndexChanged(ddlproditem, EventArgs.Empty);
                    hidproduomid.Value = dtitems.Rows[0]["UOMID"].ToString();
                    txtprodquantity.Text = dtitems.Rows[0]["ITMQTY"].ToString();
                    txtprodrate.Text = dtitems.Rows[0]["RATE"].ToString();
                    txtprodamount.Text = dtitems.Rows[0]["AMOUNT"].ToString();

                    hidprodLocation.Value = EditBindLocation(dtitems.Rows[0]["ITMID"].ToString(), dtitems.Rows[0]["SJIID"].ToString(), "2", "prod");

                    hidprodsjiid.Value = dtitems.Rows[0]["SJIID"].ToString();
                    hidprodsidid.Value = EditDetailedLocation(hidprodsjiid.Value);
                //}
            }
        }
        else if (Category == "2")
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddlproductionitems = (DropDownList)tbl_production.Rows[i].FindControl("ddlproductionitems" + i.ToString());
                    HiddenField hidproductionsjiid = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionsjiid" + i.ToString());
                    HiddenField hidproductionuomid = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionuomid" + i.ToString());
                    TextBox txtproductionquantity = (TextBox)tbl_production.Rows[i].FindControl("txtproductionquantity" + i.ToString());
                    TextBox txtproductionrate = (TextBox)tbl_production.Rows[i].FindControl("txtproductionrate" + i.ToString());
                    TextBox txtproductionamount = (TextBox)tbl_production.Rows[i].FindControl("txtproductionamount" + i.ToString());
                    HiddenField hidproductionLocation = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionLocation" + i.ToString());
                    HiddenField hidproductionsidid = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionsidid" + i.ToString());

                    ddlproductionitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    production_ddlitems_OnSelectedIndexChanged(ddlproductionitems, EventArgs.Empty);
                    hidproductionuomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtproductionquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtproductionrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtproductionamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidproductionLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "2", "");

                    hidproductionsjiid.Value = dtitems.Rows[i-1]["SJIID"].ToString();
                    hidproductionsidid.Value = EditDetailedLocation(hidproductionsjiid.Value);
                }
            }
        }
        else if (Category == "3")
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddlissueitems = (DropDownList)tbl_issue.Rows[i].FindControl("ddlissueitems" + i.ToString());
                    HiddenField hidissuesjiid = (HiddenField)tbl_issue.Rows[i].FindControl("hidissuesjiid" + i.ToString());
                    HiddenField hidissueuomid = (HiddenField)tbl_issue.Rows[i].FindControl("hidissueuomid" + i.ToString());
                    TextBox txtissuequantity = (TextBox)tbl_issue.Rows[i].FindControl("txtissuequantity" + i.ToString());
                    TextBox txtissuerate = (TextBox)tbl_issue.Rows[i].FindControl("txtissuerate" + i.ToString());
                    TextBox txtissueamount = (TextBox)tbl_issue.Rows[i].FindControl("txtissueamount" + i.ToString());
                    HiddenField hidissueLocation = (HiddenField)tbl_issue.Rows[i].FindControl("hidissueLocation" + i.ToString());
                    HiddenField hidissuesidid = (HiddenField)tbl_issue.Rows[i].FindControl("hidissuesidid" + i.ToString());

                    ddlissueitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    issue_ddlitems_OnSelectedIndexChanged(ddlissueitems, EventArgs.Empty);
                    hidissueuomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtissuequantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtissuerate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtissueamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidissueLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "3", "");

                    hidissuesjiid.Value = dtitems.Rows[i-1]["SJIID"].ToString();
                    hidissuesidid.Value = EditDetailedLocation(hidissuesjiid.Value);
                }
            }
        }
        else if (Category == "4")
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddlrecieveditems = (DropDownList)tbl_recieved.Rows[i].FindControl("ddlrecieveditems" + i.ToString());
                    HiddenField hidrecievedsjiid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedsjiid" + i.ToString());
                    HiddenField hidrecieveduomid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecieveduomid" + i.ToString());
                    TextBox txtrecievedquantity = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedquantity" + i.ToString());
                    TextBox txtrecievedrate = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedrate" + i.ToString());
                    TextBox txtrecievedamount = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedamount" + i.ToString());
                    HiddenField hidrecievedLocation = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedLocation" + i.ToString());
                    HiddenField hidrecievedsidid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedsidid" + i.ToString());

                    ddlrecieveditems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    recieved_ddlitems_OnSelectedIndexChanged(ddlrecieveditems, EventArgs.Empty);
                    hidrecieveduomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtrecievedquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtrecievedrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtrecievedamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidrecievedLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "4", "");

                    hidrecievedsjiid.Value = dtitems.Rows[i-1]["SJIID"].ToString();
                    hidrecievedsidid.Value = EditDetailedLocation(hidrecievedsjiid.Value);
                }
            }
        }
        else if (Category == "5")
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddltransferitems = (DropDownList)tbl_transfer.Rows[i].FindControl("ddltransferitems" + i.ToString());
                    HiddenField hidtransfersjiid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransfersjiid" + i.ToString());
                    HiddenField hidtransferuomid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransferuomid" + i.ToString());
                    TextBox txttransferquantity = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferquantity" + i.ToString());
                    TextBox txttransferrate = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferrate" + i.ToString());
                    TextBox txttransferamount = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferamount" + i.ToString());
                    HiddenField hidtransferLocation = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransferLocation" + i.ToString());
                    HiddenField hidtransfersidid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransfersidid" + i.ToString());

                   


                    ddltransferitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    transfer_ddlitems_OnSelectedIndexChanged(ddltransferitems, EventArgs.Empty);
                    hidtransferuomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txttransferquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txttransferrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txttransferamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();

                    hidtransferLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(), "5", "");

                    hidtransfersjiid.Value = dtitems.Rows[i-1]["SJIID"].ToString();
                    hidtransfersidid.Value = EditDetailedLocation(hidtransfersjiid.Value);
                }
            }
        }
        else if (Category == "6")
        {
            if (dtitems.Rows.Count > 0)
            {
                for (int i = 1; i <= dtitems.Rows.Count; i++)
                {
                    DropDownList ddlphysicalitems = (DropDownList)tbl_physical.Rows[i].FindControl("ddlphysicalitems" + i.ToString());
                    HiddenField hidphysicalsjiid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalsjiid" + i.ToString());
                    HiddenField hidphysicaluomid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicaluomid" + i.ToString());
                    TextBox txtphysicalquantity = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalquantity" + i.ToString());
                    TextBox txtphysicalrate = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalrate" + i.ToString());
                    TextBox txtphysicalamount = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalamount" + i.ToString());
                    HiddenField hidphysicalLocation = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalLocation" + i.ToString());
                    TextBox txtphysicalreason=(TextBox)tbl_physical.Rows[i].FindControl("txtphysicalreason"+i.ToString());
                    HiddenField hidphysicalsidid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalsidid" + i.ToString());

                    ddlphysicalitems.SelectedValue = dtitems.Rows[i - 1]["ITMID"].ToString();
                    physical_ddlitems_OnSelectedIndexChanged(ddlphysicalitems, EventArgs.Empty);
                    hidphysicaluomid.Value = dtitems.Rows[i - 1]["UOMID"].ToString();
                    txtphysicalquantity.Text = dtitems.Rows[i - 1]["ITMQTY"].ToString();
                    txtphysicalrate.Text = dtitems.Rows[i - 1]["RATE"].ToString();
                    txtphysicalamount.Text = dtitems.Rows[i - 1]["AMOUNT"].ToString();
                    txtphysicalreason.Text = dtitems.Rows[i - 1]["REASON"].ToString();
                    hidphysicalLocation.Value = EditBindLocation(dtitems.Rows[i - 1]["ITMID"].ToString(), dtitems.Rows[i - 1]["SJIID"].ToString(),"6","");

                    hidphysicalsjiid.Value = dtitems.Rows[i - 1]["SJIID"].ToString();
                    hidphysicalsidid.Value = EditDetailedLocation(hidphysicalsjiid.Value);
                }
            }
        }
    }

    protected string EditBindLocation(string ITMID, string SJIID,string Category,string subcategory)
    {
        string LocationIdandQty = string.Empty;
        if (Category == "1" && subcategory == "input")
        {
            SqlParameter[] parminloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtinloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parminloc);
            if (dtinloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtinloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString()) + '|' + dtinloc.Rows[i]["BATID"].ToString() + ':' + dtinloc.Rows[i]["WARRANTY"].ToString() + ';' + dtinloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString()) + '|' + dtinloc.Rows[i]["BATID"].ToString() + ':' + dtinloc.Rows[i]["WARRANTY"].ToString() + ';' + dtinloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString()) + '|' + dtinloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString()) + '|' + dtinloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtinloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtinloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "1" && subcategory == "output")
        {
            SqlParameter[] parmoutloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtoutloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmoutloc);
            if (dtoutloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtoutloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString()) + '|' + dtoutloc.Rows[i]["BATID"].ToString() + ':' + dtoutloc.Rows[i]["WARRANTY"].ToString() + ';' + dtoutloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString()) + '|' + dtoutloc.Rows[i]["BATID"].ToString() + ':' + dtoutloc.Rows[i]["WARRANTY"].ToString() + ';' + dtoutloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString()) + '|' + dtoutloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString()) + '|' + dtoutloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtoutloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtoutloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "2" && subcategory == "prod")
        {
            SqlParameter[] parmprodloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtprodloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmprodloc);
            if (dtprodloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtprodloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString()) + '|' + dtprodloc.Rows[i]["BATID"].ToString() + ':' + dtprodloc.Rows[i]["WARRANTY"].ToString() + ';' + dtprodloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString()) + '|' + dtprodloc.Rows[i]["BATID"].ToString() + ':' + dtprodloc.Rows[i]["WARRANTY"].ToString() + ';' + dtprodloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString()) + '|' + dtprodloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString()) + '|' + dtprodloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtprodloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtprodloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "2")
        {
            SqlParameter[] parmproductionloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtproductionloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmproductionloc);
            if (dtproductionloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtproductionloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString()) + '|' + dtproductionloc.Rows[i]["BATID"].ToString() + ':' + dtproductionloc.Rows[i]["WARRANTY"].ToString() + ';' + dtproductionloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString()) + '|' + dtproductionloc.Rows[i]["BATID"].ToString() + ':' + dtproductionloc.Rows[i]["WARRANTY"].ToString() + ';' + dtproductionloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString()) + '|' + dtproductionloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString()) + '|' + dtproductionloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtproductionloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtproductionloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "3")
        {
            SqlParameter[] parmissueloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtissueloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmissueloc);
            if (dtissueloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtissueloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString()) + '|' + dtissueloc.Rows[i]["BATID"].ToString() + ':' + dtissueloc.Rows[i]["WARRANTY"].ToString() + ';' + dtissueloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString()) + '|' + dtissueloc.Rows[i]["BATID"].ToString() + ':' + dtissueloc.Rows[i]["WARRANTY"].ToString() + ';' + dtissueloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString()) + '|' + dtissueloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString()) + '|' + dtissueloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtissueloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtissueloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "4")
        {
            SqlParameter[] parmreceiptloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtreceiptloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmreceiptloc);
            if (dtreceiptloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtreceiptloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString()) + '|' + dtreceiptloc.Rows[i]["BATID"].ToString() + ':' + dtreceiptloc.Rows[i]["WARRANTY"].ToString() + ';' + dtreceiptloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString()) + '|' + dtreceiptloc.Rows[i]["BATID"].ToString() + ':' + dtreceiptloc.Rows[i]["WARRANTY"].ToString() + ';' + dtreceiptloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString()) + '|' + dtreceiptloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString()) + '|' + dtreceiptloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtreceiptloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtreceiptloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "5")
        {
            SqlParameter[] parmtransferloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dttransferloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmtransferloc);
            if (dttransferloc.Rows.Count > 0)
            {
                for (int i = 0; i < dttransferloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString()) + '|' + dttransferloc.Rows[i]["BATID"].ToString() + ':' + dttransferloc.Rows[i]["WARRANTY"].ToString() + ';' + dttransferloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString()) + '|' + dttransferloc.Rows[i]["BATID"].ToString() + ':' + dttransferloc.Rows[i]["WARRANTY"].ToString() + ';' + dttransferloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString()) + '|' + dttransferloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString()) + '|' + dttransferloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dttransferloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dttransferloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }
        else if (Category == "6")
        {
            SqlParameter[] parmphysicalloc = { 
                                        new SqlParameter("SJIID",SJIID)
                                       };
            DataTable dtphysicalloc = DU.getdatausingprocedure("usp_ivr_STKJRNL_get_Edit_ItemsDetails", parmphysicalloc);
            if (dtphysicalloc.Rows.Count > 0)
            {
                for (int i = 0; i < dtphysicalloc.Rows.Count; i++)
                {
                    if (isBatchEnabled(ITMID) && isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString()) + '|' + dtphysicalloc.Rows[i]["BATID"].ToString() + ':' + dtphysicalloc.Rows[i]["WARRANTY"].ToString() + ';' + dtphysicalloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString()) + '|' + dtphysicalloc.Rows[i]["BATID"].ToString() + ':' + dtphysicalloc.Rows[i]["WARRANTY"].ToString() + ';' + dtphysicalloc.Rows[i]["WARRANTYPERIOD"].ToString();
                        }
                    }
                    else if (isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString()) + '|' + dtphysicalloc.Rows[i]["BATID"].ToString();
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString()) + '|' + dtphysicalloc.Rows[i]["BATID"].ToString();
                        }
                    }
                    else if (!isBatchEnabled(ITMID) && !isWarrantyEnabled(ITMID))
                    {
                        if (i == 0)
                        {
                            LocationIdandQty += dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString());
                        }
                        else if (i > 0)
                        {
                            LocationIdandQty += "/" + dtphysicalloc.Rows[i]["whsid"].ToString() + ',' + string.Format("{0:0.00}", dtphysicalloc.Rows[i]["DETQTY"].ToString());
                        }
                    }
                }
            }
        }

        return LocationIdandQty;    
    }

    protected string EditDetailedLocation(string SJIID)
    {
        string Detailid = string.Empty;
        if (SJIID != string.Empty)
        {
            SqlParameter[] parma = {
                                    new SqlParameter("@SJIID",SJIID)
                                   };
            DataTable dtDetaillocation = DU.getdatausingprocedure("usp_ivr_SKKJRNL_Edit_ITemsDetails", parma);
            if (dtDetaillocation.Rows.Count > 0)
            {
                for (int i = 0; i < dtDetaillocation.Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        Detailid += dtDetaillocation.Rows[i]["SIDID"].ToString();
                    }
                    else if (i > 0)
                    {
                        Detailid += "/" + dtDetaillocation.Rows[i]["SIDID"].ToString();
                    }
                }
            }
        }
        return Detailid;
    }

    protected void EditBindOtherDetails()
    {
        SqlParameter[] parmaother = {
                                new SqlParameter("@SJRID",reqSJRID)
                               };
        DataTable dtother = DU.getdatausingprocedure("usp_ivr_STKJRNL_OtherDetails", parmaother);
        if (dtother.Rows.Count > 0)
        {
            txtdetailsnarrations.Text = "";
            txtdetailspreparedby.Text = "";
            txtdetailsremarks.Text = "";
            txtdetailscheckedby.Text = "";
            txtdetailsnote.Text = "";
            txtdetailsauthorisedsignatory.Text = "";

            txtdetailsnarrations.Text = dtother.Rows[0]["NARRATION"].ToString();
            txtdetailspreparedby.Text = dtother.Rows[0]["PREPAREDBY"].ToString();
            txtdetailsremarks.Text = dtother.Rows[0]["REMARKS"].ToString();
            txtdetailscheckedby.Text = dtother.Rows[0]["CHECKEDBY"].ToString();
            txtdetailsnote.Text = dtother.Rows[0]["NOTE"].ToString();
            txtdetailsauthorisedsignatory.Text = dtother.Rows[0]["AUTHRSDSIGNAT"].ToString();
        }
    }

    protected void BindJounalFormat()
    {
        SqlParameter[] prrr = { 
                                new SqlParameter("@trantype",7)
                              };
        DataTable dtformate = DU.getdatausingprocedure("USP_IVR_GetTransactionFormat", prrr);
        if (dtformate.Rows.Count > 0)
        {
            ddljrnFormate.DataSource = dtformate;
            ddljrnFormate.DataTextField = "FORMATNAME";
            ddljrnFormate.DataValueField = "TFOID";  //Not  STKJRNLOPT
            ddljrnFormate.DataBind();

            ListItem li = new ListItem("--- Select Format ---", "0");
            ddljrnFormate.Items.Insert(0, li);
            li.Selected = true;
        }
    }
    protected void visibleInvisible()
    {
        hid_TFOID.Value = "";
        string strsql = "Select STKJRNLOPT from IVR_TRANFORMAT Where TFOID='" + ddljrnFormate.SelectedValue + "'";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            if (DT.Rows[0]["STKJRNLOPT"].ToString() == "1") // Stock Journal
            {
                hid_TFOID.Value = "1";

                tbl_inputoutput.Visible = true;
                tbl_input_btn.Visible = true;
                tbl_output_btn.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tdfromto.Visible = false;
                tbl_physical.Visible = false;
                tbl_production.Visible = false;
                tbl_production_first.Visible = false;
                spnconsume.Visible = false;
                tbl_transfer.Visible = false;
                tbl_recieved.Visible = false;
                tbl_production.Visible = false;
                tbl_jounal.Visible = false;
                tbl_issue.Visible = false;
                tbl_issue_btn.Visible = false;
                tbl_production_btn.Visible = false;
                tbl_recieved_btn.Visible = false;
                tbl_transfer_btn.Visible = false;
                tbl_physical_btn.Visible = false;

            }
            else if (DT.Rows[0]["STKJRNLOPT"].ToString() == "2")  // Production Journal
            {
                hid_TFOID.Value = "2";

                tbl_production_first.Visible = true;
                tbl_production_btn.Visible = true;
                spnconsume.Visible = true;
                tbl_production.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tbl_inputoutput.Visible = false;
                tdfromto.Visible = false;
                tbl_physical.Visible = false;
                tbl_transfer.Visible = false;
                tbl_recieved.Visible = false;
                tbl_jounal.Visible = false;
                tbl_issue.Visible = false;
                tbl_issue_btn.Visible = false;
                tbl_input_btn.Visible = false;
                tbl_output_btn.Visible = false;
                tbl_recieved_btn.Visible = false;
                tbl_transfer_btn.Visible = false;
                tbl_physical_btn.Visible = false;

                BindProductionITem();
                
            }
            else if (DT.Rows[0]["STKJRNLOPT"].ToString() == "3")  // Stock Issue
            {
                hid_TFOID.Value = "3";

                tbl_issue.Visible = true;
                tbl_issue_btn.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tbl_inputoutput.Visible = false;
                tdfromto.Visible = false;
                tbl_physical.Visible = false;
                tbl_production.Visible = false;
                tbl_production_first.Visible = false;
                spnconsume.Visible = false;
                tbl_transfer.Visible = false;
                tbl_recieved.Visible = false;
                tbl_production.Visible = false;
                tbl_jounal.Visible = false;
                tbl_input_btn.Visible = false;
                tbl_output_btn.Visible = false;
                tbl_production_btn.Visible = false;
                tbl_recieved_btn.Visible = false;
                tbl_transfer_btn.Visible = false;
                tbl_physical_btn.Visible = false;
            }
            else if (DT.Rows[0]["STKJRNLOPT"].ToString() == "4")  // Stock Receipt
            {
                hid_TFOID.Value = "4";

                tbl_recieved.Visible = true;
                tbl_recieved_btn.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tbl_inputoutput.Visible = false;
                tdfromto.Visible = false;
                tbl_physical.Visible = false;
                tbl_production.Visible = false;
                spnconsume.Visible = false;
                tbl_transfer.Visible = false;
                tbl_production.Visible = false;
                tbl_production_first.Visible = false;
                tbl_jounal.Visible = false;
                tbl_issue.Visible = false;
                tbl_issue_btn.Visible = false;
                tbl_input_btn.Visible = false;
                tbl_output_btn.Visible = false;
                tbl_production_btn.Visible = false;
                tbl_transfer_btn.Visible = false;
                tbl_physical_btn.Visible = false;
            }
            else if (DT.Rows[0]["STKJRNLOPT"].ToString() == "5")  // Stock Transfer
            {
                hid_TFOID.Value = "5";

                tdfromto.Visible = true;
                tbl_transfer.Visible = true;
                tbl_transfer_btn.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tbl_inputoutput.Visible = false;
                tbl_physical.Visible = false;
                tbl_production.Visible = false;
                tbl_production_first.Visible = false;
                spnconsume.Visible = false;
                tbl_recieved.Visible = false;
                tbl_production.Visible = false;
                tbl_jounal.Visible = false;
                tbl_issue.Visible = false;
                tbl_issue_btn.Visible = false;
                tbl_input_btn.Visible = false;
                tbl_output_btn.Visible = false;
                tbl_production_btn.Visible = false;
                tbl_recieved_btn.Visible = false;
                tbl_physical_btn.Visible = false;
            }
            else if (DT.Rows[0]["STKJRNLOPT"].ToString() == "6")  // Physical Stock
            {
                hid_TFOID.Value = "6";

                tbl_physical.Visible = true;
                tbl_physical_btn.Visible = true;
                tbl_details.Visible = true;
                tblbtn.Visible = true;

                tbl_transfer.Visible = false;
                tbl_recieved.Visible = false;
                tbl_production.Visible = false;
                tbl_jounal.Visible = false;
                tbl_issue.Visible = false;
                tbl_inputoutput.Visible = false;
                tbl_production.Visible = false;
                tbl_production_first.Visible = false;
                spnconsume.Visible = false;
                tdfromto.Visible = false;
                tbl_issue_btn.Visible = false;
                tbl_input_btn.Visible = false;
                tbl_output_btn.Visible = false;
                tbl_production_btn.Visible = false;
                tbl_recieved_btn.Visible = false;
                tbl_transfer_btn.Visible = false;
            }

           
        }   
    }
    protected void BindJournalNo(string TFOID)
    {
        lblMsg.Text = "";
        int finyear = 0;
        if (Session["FINYEAR"] != null)
        {
            finyear = Convert.ToInt32(Session["FINYEAR"].ToString());
        }
        else
        {
            Response.Redirect("~/SessionExpired.aspx");
        }

        SqlParameter[] parma = {
                                  new SqlParameter("@SJRID",Convert.ToInt32(reqSJRID.ToString())),
                                 };
        DataTable dtdcformatno = DU.getdatausingprocedure("usp_ivr_Get_STKJRNL_by_SJRID", parma);
        if (dtdcformatno.Rows.Count > 0)
        {
            txtPrefix.Enabled = false;
            txtjrnno.Enabled = false;
            txtSuffix.Enabled = false;

            txtPrefix.Text = dtdcformatno.Rows[0]["NUMPREFIX"].ToString();
            txtjrnno.Text = dtdcformatno.Rows[0]["sjrnum"].ToString();
            txtSuffix.Text = dtdcformatno.Rows[0]["NUMSUFFIX"].ToString();
        }
        else
        {
            txtPrefix.Text = "";
            txtjrnno.Text = "";
            txtSuffix.Text = "";
        }
    }
    protected void ddljrnFormate_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblMsg.Text = "";
        if (ddljrnFormate.SelectedValue != "0")
        {
            BindJournalNo(ddljrnFormate.SelectedValue.ToString());
            visibleInvisible();
            CheckTranFormat();
            ClearForm();
            if (hid_TFOID.Value.ToString() == "2")
            {
                ResetTableControl(tbl_production_first);
            }
            ResetTableControl(tbl_input);
            ResetTableControl(tbl_output);
            ResetTableControl(tbl_production);
            ResetTableControl(tbl_issue);
            ResetTableControl(tbl_recieved);
            ResetTableControl(tbl_transfer);
            ResetTableControl(tbl_physical);
        }
    }

    #region Transfer
    protected void ddlFromLoacation_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(ddlfromLoacation.SelectedValue!="0")
        {
            hidfromLoacation.Value = ddlfromLoacation.SelectedValue.ToString();
            transfer_BindJavaScriptItemQtyPopUp();
        }
    }
    protected void ddlToLoacation_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlToLoacation.SelectedValue != "0")
        {
            hidToLoacation.Value = ddlToLoacation.SelectedValue.ToString();
            transfer_BindJavaScriptItemQtyPopUp();
        }
    }
    #endregion
    protected void CheckTranFormat()
    {
        if (ddljrnFormate.SelectedValue != "0")
        {
             SqlParameter[] parrr = { new SqlParameter("@TFOID",ddljrnFormate.SelectedValue) };
            DataTable dtpermission = DU.getdatausingprocedure("CheckTranFormat", parrr);
            if (dtpermission.Rows.Count > 0)
            {
                if (dtpermission.Rows[0]["NARRATION"].ToString() == "True")
                {
                    txtdetailsnarrations.Enabled = true;
                    txtdetailsnarrations.CssClass = "input";
                }
                else
                {
                    txtdetailsnarrations.Enabled = false;
                    txtdetailsnarrations.CssClass = "DisableInput";

                }
                if (dtpermission.Rows[0]["PREPAREDBY"].ToString() == "True")
                {
                    txtdetailspreparedby.Enabled = true;
                    txtdetailspreparedby.CssClass = "input";
                }
                else
                {
                    txtdetailspreparedby.Enabled = false;
                    txtdetailspreparedby.CssClass = "DisableInput";
                }
                if (dtpermission.Rows[0]["REMARKS"].ToString() == "True")
                {
                    txtdetailsremarks.Enabled = true;
                    txtdetailsremarks.CssClass = "input";
                }
                else
                {
                    txtdetailsremarks.Enabled = false;
                    txtdetailsremarks.CssClass = "DisableInput";
                }
                if (dtpermission.Rows[0]["CHECKEDBY"].ToString() == "True")
                {
                    txtdetailscheckedby.Enabled = true;
                    txtdetailscheckedby.CssClass = "input";
                }
                else
                {
                    txtdetailscheckedby.Enabled = false;
                    txtdetailscheckedby.CssClass = "DisableInput";
                }
                if (dtpermission.Rows[0]["NOTE"].ToString() == "True")
                {
                    txtdetailsnote.Enabled = true;
                    txtdetailsnote.CssClass = "input";
                }
                else
                {
                    txtdetailsnote.Enabled = false;
                    txtdetailsnote.CssClass = "DisableInput";
                }
                if (dtpermission.Rows[0]["AUTHSIGNATORY"].ToString() == "True")
                {
                    txtdetailsauthorisedsignatory.Enabled = true;
                    txtdetailsauthorisedsignatory.CssClass = "input";
                }
                else
                {
                    txtdetailsauthorisedsignatory.Enabled = false;
                    txtdetailsauthorisedsignatory.CssClass = "DisableInput";
                }
            }
        }
    }
    protected void ClearForm()
    {
        if (hid_TFOID.Value == "1")  // Journal input
        {
            listinputcounter = (List<string>)ViewState["listinputcounter"];
            listddlinputitems = (List<string>)ViewState["listddlinputitems"];
            listtxtinputunit = (List<string>)ViewState["listtxtinputunit"];
            listhidinputuomid = (List<string>)ViewState["listhidinputuomid"];
            listtxtinputquantity = (List<string>)ViewState["listtxtinputquantity"];
            listbtninputqty = (List<string>)ViewState["listbtninputqty"];
            listhidinputLocation = (List<string>)ViewState["listhidinputLocation"];
            listtxtinputrate = (List<string>)ViewState["listtxtinputrate"];
            listtxtinputamount = (List<string>)ViewState["listtxtinputamount"];
            if (tbl_input.Rows.Count > 3)
            {
                for (int i = tbl_input.Rows.Count; i > 3; i--)
                {
                    if (listinputcounter != null)
                    {
                        listinputcounter.RemoveAt(i - 4);
                        listddlinputitems.RemoveAt(i - 4);
                        listtxtinputunit.RemoveAt(i - 4);
                        listhidinputuomid.RemoveAt(i - 4);
                        listtxtinputquantity.RemoveAt(i - 4);
                        listbtninputqty.RemoveAt(i - 4);
                        listhidinputLocation.RemoveAt(i - 4);
                        listtxtinputrate.RemoveAt(i - 4);
                        listtxtinputamount.RemoveAt(i - 4);
                    }
                    tbl_input.Rows.RemoveAt(i - 1);
                }
                hidinputCount.Value = "2";
                ResetTableControl(tbl_input);
            }
        }
        if (hid_TFOID.Value == "1")  // Journal output
        {
            listoutputcounter = (List<string>)ViewState["listoutputcounter"];
            listddloutputitems = (List<string>)ViewState["listddloutputitems"];
            listtxtoutputunit = (List<string>)ViewState["listtxtoutputunit"];
            listhidoutputuomid = (List<string>)ViewState["listhidoutputuomid"];
            listtxtoutputquantity = (List<string>)ViewState["listtxtoutputquantity"];
            listbtnoutputqty = (List<string>)ViewState["listbtnoutputqty"];
            listhidoutputLocation = (List<string>)ViewState["listhidoutputLocation"];
            listtxtoutputrate = (List<string>)ViewState["listtxtoutputrate"];
            listtxtoutputamount = (List<string>)ViewState["listtxtoutputamount"];
            if (tbl_output.Rows.Count > 3)
            {
                for (int i = tbl_output.Rows.Count; i > 3; i--)
                {
                    if (listoutputcounter != null)
                    {
                        listoutputcounter.RemoveAt(i - 4);
                        listddloutputitems.RemoveAt(i - 4);
                        listtxtoutputunit.RemoveAt(i - 4);
                        listhidoutputuomid.RemoveAt(i - 4);
                        listtxtoutputquantity.RemoveAt(i - 4);
                        listbtnoutputqty.RemoveAt(i - 4);
                        listhidoutputLocation.RemoveAt(i - 4);
                        listtxtoutputrate.RemoveAt(i - 4);
                        listtxtoutputamount.RemoveAt(i - 4);
                    }
                    tbl_output.Rows.RemoveAt(i - 1);
                }
                hidoutputCount.Value = "2";
                ResetTableControl(tbl_output);
            }
        }
        if (hid_TFOID.Value == "2")  // production
        {
            listproductioncounter = (List<string>)ViewState["listproductioncounter"];
            listddlproductionitems = (List<string>)ViewState["listddlproductionitems"];
            listtxtproductionunit = (List<string>)ViewState["listtxtproductionunit"];
            listhidproductionuomid = (List<string>)ViewState["listhidproductionuomid"];
            listtxtproductionquantity = (List<string>)ViewState["listtxtproductionquantity"];
            listbtnproductionqty = (List<string>)ViewState["listbtnproductionqty"];
            listhidproductionLocation = (List<string>)ViewState["listhidproductionLocation"];
            listtxtproductionrate = (List<string>)ViewState["listtxtproductionrate"];
            listtxtproductionamount = (List<string>)ViewState["listtxtproductionamount"];
            if (tbl_production.Rows.Count > 3)
            {
                for (int i = tbl_production.Rows.Count; i > 3; i--)
                {
                    if (listproductioncounter != null)
                    {
                        listproductioncounter.RemoveAt(i - 4);
                        listddlproductionitems.RemoveAt(i - 4);
                        listtxtproductionunit.RemoveAt(i - 4);
                        listhidproductionuomid.RemoveAt(i - 4);
                        listtxtproductionquantity.RemoveAt(i - 4);
                        listbtnproductionqty.RemoveAt(i - 4);
                        listhidproductionLocation.RemoveAt(i - 4);
                        listtxtproductionrate.RemoveAt(i - 4);
                        listtxtproductionamount.RemoveAt(i - 4);
                    }
                    tbl_production.Rows.RemoveAt(i - 1);
                }
                hidproductionCount.Value = "2";
                int productionCounter = 2;
                ResetTableControl(tbl_production);
            }
        }
        if (hid_TFOID.Value == "3")  // Issue
        {
                listissuecounter = (List<string>)ViewState["listissuecounter"];
                listddlissueitems = (List<string>)ViewState["listddlissueitems"];
                listtxtissueunit = (List<string>)ViewState["listtxtissueunit"];
                listhidissueuomid = (List<string>)ViewState["listhidissueuomid"];
                listtxtissuequantity = (List<string>)ViewState["listtxtissuequantity"];
                listbtnissueqty = (List<string>)ViewState["listbtnissueqty"];
                listhidissueLocation = (List<string>)ViewState["listhidissueLocation"];
                listtxtissuerate = (List<string>)ViewState["listtxtissuerate"];
                listtxtissueamount = (List<string>)ViewState["listtxtissueamount"];
                if (tbl_issue.Rows.Count > 3)
                {
                    for (int i = tbl_issue.Rows.Count; i > 3; i--)
                    {
                        if (listissuecounter != null)
                        {
                            listissuecounter.RemoveAt(i - 4);
                            listddlissueitems.RemoveAt(i - 4);
                            listtxtissueunit.RemoveAt(i - 4);
                            listhidissueuomid.RemoveAt(i - 4);
                            listtxtissuequantity.RemoveAt(i - 4);
                            listbtnissueqty.RemoveAt(i - 4);
                            listhidissueLocation.RemoveAt(i - 4);
                            listtxtissuerate.RemoveAt(i - 4);
                            listtxtissueamount.RemoveAt(i - 4);
                        }
                        tbl_issue.Rows.RemoveAt(i-1);
                    }
                    
                    hidissueCount.Value = "2";
                    ResetTableControl(tbl_issue);
                }
        }
        if (hid_TFOID.Value == "4")  // recieved
        {
            listrecievedcounter = (List<string>)ViewState["listrecievedcounter"];
            listddlrecieveditems = (List<string>)ViewState["listddlrecieveditems"];
            listtxtrecievedunit = (List<string>)ViewState["listtxtrecievedunit"];
            listhidrecieveduomid = (List<string>)ViewState["listhidrecieveduomid"];
            listtxtrecievedquantity = (List<string>)ViewState["listtxtrecievedquantity"];
            listbtnrecievedqty = (List<string>)ViewState["listbtnrecievedqty"];
            listhidrecievedLocation = (List<string>)ViewState["listhidrecievedLocation"];
            listtxtrecievedrate = (List<string>)ViewState["listtxtrecievedrate"];
            listtxtrecievedamount = (List<string>)ViewState["listtxtrecievedamount"];
            if (tbl_recieved.Rows.Count > 3)
            {
                for (int i = tbl_recieved.Rows.Count; i > 3; i--)
                {
                    if (listrecievedcounter != null)
                    {
                        listrecievedcounter.RemoveAt(i - 4);
                        listddlrecieveditems.RemoveAt(i - 4);
                        listtxtrecievedunit.RemoveAt(i - 4);
                        listhidrecieveduomid.RemoveAt(i - 4);
                        listtxtrecievedquantity.RemoveAt(i - 4);
                        listbtnrecievedqty.RemoveAt(i - 4);
                        listhidrecievedLocation.RemoveAt(i - 4);
                        listtxtrecievedrate.RemoveAt(i - 4);
                        listtxtrecievedamount.RemoveAt(i - 4);
                    }
                    tbl_recieved.Rows.RemoveAt(i - 1);
                }
                hidrecievedCount.Value = "2";
                ResetTableControl(tbl_recieved);
            }
        }
        if (hid_TFOID.Value == "5")  // transfer
        {
            listtransfercounter = (List<string>)ViewState["listtransfercounter"];
            listddltransferitems = (List<string>)ViewState["listddltransferitems"];
            listtxttransferunit = (List<string>)ViewState["listtxttransferunit"];
            listhidtransferuomid = (List<string>)ViewState["listhidtransferuomid"];
            listtxttransferquantity = (List<string>)ViewState["listtxttransferquantity"];
            listbtntransferqty = (List<string>)ViewState["listbtntransferqty"];
            listhidtransferLocation = (List<string>)ViewState["listhidtransferLocation"];
            listtxttransferrate = (List<string>)ViewState["listtxttransferrate"];
            listtxttransferamount = (List<string>)ViewState["listtxttransferamount"];
            if (tbl_transfer.Rows.Count > 3)
            {
                for (int i = tbl_transfer.Rows.Count; i > 3; i--)
                {
                    if (listtransfercounter != null)
                    {
                        listtransfercounter.RemoveAt(i - 4);
                        listddltransferitems.RemoveAt(i - 4);
                        listtxttransferunit.RemoveAt(i - 4);
                        listhidtransferuomid.RemoveAt(i - 4);
                        listtxttransferquantity.RemoveAt(i - 4);
                        listbtntransferqty.RemoveAt(i - 4);
                        listhidtransferLocation.RemoveAt(i - 4);
                        listtxttransferrate.RemoveAt(i - 4);
                        listtxttransferamount.RemoveAt(i - 4);
                    }
                    tbl_transfer.Rows.RemoveAt(i - 1);
                }
                hidtransferCount.Value = "2";
                ResetTableControl(tbl_transfer);
            }
        }
        if (hid_TFOID.Value == "6")  // physical
        {
            listphysicalcounter = (List<string>)ViewState["listphysicalcounter"];
            listddlphysicalitems = (List<string>)ViewState["listddlphysicalitems"];
            listtxtphysicalunit = (List<string>)ViewState["listtxtphysicalunit"];
            listhidphysicaluomid = (List<string>)ViewState["listhidphysicaluomid"];
            listtxtphysicalquantity = (List<string>)ViewState["listtxtphysicalquantity"];
            listbtnphysicalqty = (List<string>)ViewState["listbtnphysicalqty"];
            listhidphysicalLocation = (List<string>)ViewState["listhidphysicalLocation"];
            listtxtphysicalrate = (List<string>)ViewState["listtxtphysicalrate"];
            listtxtphysicalamount = (List<string>)ViewState["listtxtphysicalamount"];
            listtxtphysicalreason = (List<string>)ViewState["listtxtphysicalreason"];
            if (tbl_physical.Rows.Count > 3)
            {
                for (int i = tbl_physical.Rows.Count; i > 3; i--)
                {
                    if (listphysicalcounter != null)
                    {
                        listphysicalcounter.RemoveAt(i - 4);
                        listddlphysicalitems.RemoveAt(i - 4);
                        listtxtphysicalunit.RemoveAt(i - 4);
                        listhidphysicaluomid.RemoveAt(i - 4);
                        listtxtphysicalquantity.RemoveAt(i - 4);
                        listbtnphysicalqty.RemoveAt(i - 4);
                        listhidphysicalLocation.RemoveAt(i - 4);
                        listtxtphysicalrate.RemoveAt(i - 4);
                        listtxtphysicalamount.RemoveAt(i - 4);
                        listtxtphysicalreason.RemoveAt(i - 4);
                    }
                    tbl_physical.Rows.RemoveAt(i - 1);
                }
                hidphysicalCount.Value = "2";
                ResetTableControl(tbl_physical);
            }
        }
    }
    protected void ResetTableControl(Control Tableid)
    {
        foreach (Control c in Tableid.Controls)
        {
            if (c.GetType() == typeof(TextBox))
            {
                ((TextBox)(c)).Text = string.Empty;
            }
            if (c.GetType() == typeof(HiddenField))
            {
                ((HiddenField)(c)).Value = string.Empty;
            }
            if (c.GetType() == typeof(DropDownList))
            {
                ((DropDownList)(c)).SelectedIndex = 0;
            }
            if (c.HasControls())
            {
                ResetTableControl(c);
            }
        }
    }
    protected void BindProductionITem()
    {
        DataTable dtBOMITEM = DU.getdatausingprocedure("USP_IVR_GETITEM_BOM");
        if (dtBOMITEM.Rows.Count > 0)
        {
            ddlproditem.DataSource = dtBOMITEM;
            ddlproditem.DataTextField = "ITEM";
            ddlproditem.DataValueField = "ITMID";
            ddlproditem.DataBind();

            ListItem li = new ListItem("--- Select Items ---");
            ddlproditem.Items.Insert(0, li);
            li.Selected = true;
        }
    }
    protected void prod_ddlitems_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        ResetTableControl(tbl_production);
        ClearForm();
        txtprodquantity.Text=string.Empty;
        hidprodLocation.Value = string.Empty;
        hidproduomid.Value = string.Empty;
        txtprodunit.Text = string.Empty;
        txtprodrate.Text = string.Empty;
        txtprodamount.Text = string.Empty;
        DropDownList ddl = (DropDownList)sender;

        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddlproditem.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);
            if (dtuom.Rows.Count > 0)
            {
                txtprodunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
                hidproduomid.Value = dtuom.Rows[0]["UOMID"].ToString();
                //hidprodBOM.Value = "";
                
            }
            prod_BindJavaScriptItemQtyPopUp();
            
        }
        else
        {
            txtprodunit.Text = "";
            hidproduomid.Value = "";
        }
    }
    protected void prod_BindJavaScriptItemQtyPopUp()
    {
        btnprodQty.Attributes.Add("onclick", "return GetQuantityProd('" + ddlproditem.SelectedValue + "', '" + txtprodquantity.ClientID.ToString() + "', '" + hidprodLocation.ClientID.ToString() + "');");
    }
    protected void ClearPRODTable()
    {
        ddlproditem.SelectedIndex = 0;
        txtprodquantity.Text = string.Empty;
        hidprodLocation.Value = string.Empty;
        txtprodunit.Text = string.Empty;
        hidproduomid.Value = string.Empty;
        txtprodrate.Text = string.Empty;
        txtprodamount.Text = string.Empty;
    }
    protected void BindItemBom(object sender, EventArgs e)
    {
            ResetTableControl(tbl_production);
            ClearForm();
        if (txtprodquantity.Text != string.Empty)
        {
            
            DataTable dtproditem = DU.getdata("select itmid,itmqty,uomid,(select uomsymbol from IVR_UOM where uomid=ivr_bomitem.uomid)as uomsymbol from ivr_bomitem where bomid=(select bomid from ivr_bom where itmid=" + ddlproditem.SelectedValue + ")");
            if (dtproditem.Rows.Count > 0)
            {
                
                if (dtproditem.Rows.Count > 2)
                {
                        productionCounter = 2;
                        for (int i = 2; i < dtproditem.Rows.Count; i++)
                        {
                            production_ADDMORE("production");
                        }
                    
                }
                for (int i = 1; i <= dtproditem.Rows.Count; i++)
                {
                    DropDownList ddlproductionitems = (DropDownList)tbl_production.Rows[i].FindControl("ddlproductionitems" + i.ToString());
                    TextBox txtproductionquantity = (TextBox)tbl_production.Rows[i].FindControl("txtproductionquantity" + i.ToString());
                    TextBox txtproductionunit = (TextBox)tbl_production.Rows[i].FindControl("txtproductionunit" + i.ToString());
                    HiddenField hidproductionuomid = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionuomid" + i.ToString());

                    ddlproductionitems.SelectedValue = dtproditem.Rows[i - 1]["itmid"].ToString();
                    txtproductionquantity.Text = (Convert.ToDouble(dtproditem.Rows[i - 1]["itmqty"].ToString()) * Convert.ToDouble(txtprodquantity.Text)).ToString();
                    txtproductionunit.Text = dtproditem.Rows[i - 1]["uomsymbol"].ToString();
                    hidproductionuomid.Value = dtproditem.Rows[i - 1]["uomid"].ToString();
                }
           }
        }
        production_BindJavaScriptItemQtyPopUp();
    }
    #endregion Common Mendatory

    #region Issue Primary Function

    protected void Issue_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void issue_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(13);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_issue.Rows[rowno].FindControl("txtissueunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_issue.Rows[rowno].FindControl("hidissueuomid" + rowno.ToString());
        TextBox txtissuequantity = (TextBox)tbl_issue.Rows[rowno].FindControl("txtissuequantity" + rowno.ToString());
        TextBox txtissuerate = (TextBox)tbl_issue.Rows[rowno].FindControl("txtissuerate" + rowno.ToString());
        TextBox txtissueamount = (TextBox)tbl_issue.Rows[rowno].FindControl("txtissueamount" + rowno.ToString());
        HiddenField hidissueLocation = (HiddenField)tbl_issue.Rows[rowno].FindControl("hidissueLocation" + rowno.ToString());

        txtissuequantity.Text = string.Empty;
        txtissuerate.Text = string.Empty;
        txtissueamount.Text = string.Empty;
        hidissueLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            Issue_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void Issue_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidissueCount.Value.ToString());
        for (int i = 1; i <= intCount; i++)
        {
            DropDownList ddlitems = (DropDownList)tbl_issue.Rows[i].FindControl("ddlissueitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_issue.Rows[i].FindControl("txtissuequantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_issue.Rows[i].FindControl("hidissueLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_issue.Rows[i].FindControl("btnissueqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }

    #endregion

    #region recieved Primary Function

    protected void recieved_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void recieved_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(16);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_recieved.Rows[rowno].FindControl("txtrecievedunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_recieved.Rows[rowno].FindControl("hidrecieveduomid" + rowno.ToString());
        TextBox txtrecievedquantity = (TextBox)tbl_recieved.Rows[rowno].FindControl("txtrecievedquantity" + rowno.ToString());
        TextBox txtrecievedrate = (TextBox)tbl_recieved.Rows[rowno].FindControl("txtrecievedrate" + rowno.ToString());
        TextBox txtrecievedamount = (TextBox)tbl_recieved.Rows[rowno].FindControl("txtrecievedamount" + rowno.ToString());
        HiddenField hidrecievedLocation = (HiddenField)tbl_recieved.Rows[rowno].FindControl("hidrecievedLocation" + rowno.ToString());

        txtrecievedquantity.Text = string.Empty;
        txtrecievedrate.Text = string.Empty;
        txtrecievedamount.Text = string.Empty;
        hidrecievedLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            recieved_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void recieved_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidrecievedCount.Value);
        for (int i = 1; i <= intCount; i++)
        {
            DropDownList ddlitems = (DropDownList)tbl_recieved.Rows[i].FindControl("ddlrecieveditems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_recieved.Rows[i].FindControl("btnrecievedqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString()+ "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }

    #endregion End recieved

    #region transfer Primary Function

    protected void transfer_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void transfer_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(16);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_transfer.Rows[rowno].FindControl("txttransferunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_transfer.Rows[rowno].FindControl("hidtransferuomid" + rowno.ToString());
        TextBox txttransferquantity = (TextBox)tbl_transfer.Rows[rowno].FindControl("txttransferquantity" + rowno.ToString());
        TextBox txttransferrate = (TextBox)tbl_transfer.Rows[rowno].FindControl("txttransferrate" + rowno.ToString());
        TextBox txttransferamount = (TextBox)tbl_transfer.Rows[rowno].FindControl("txttransferamount" + rowno.ToString());
        HiddenField hidtransferLocation =(HiddenField) tbl_transfer.Rows[rowno].FindControl("hidtransferLocation" + rowno.ToString());

        txttransferquantity.Text = string.Empty;
        txttransferrate.Text = string.Empty;
        txttransferamount.Text = string.Empty;
        hidtransferLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            transfer_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void transfer_BindJavaScriptItemQtyPopUp()
    {
        string SendLoacationId = "";
        if (hid_TFOID.Value.ToString() == "5")
        {
            //if (hidfromLoacation.Value != string.Empty)
            //{
                //SendLoacationId = hidfromLoacation.Value.ToString();
                SendLoacationId = ddlfromLoacation.SelectedValue.ToString();
            //}
        }
        int intCount = Convert.ToInt32(hidtransferCount.Value);
        for (int i = 1; i <= intCount; i++)
        {
            DropDownList ddlitems = (DropDownList)tbl_transfer.Rows[i].FindControl("ddltransferitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransferLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_transfer.Rows[i].FindControl("btntransferqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantityTransfer('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "','" + SendLoacationId + "');");
        }

    }
    protected void transfer_BindLocation()
    {
        string  strsql = "Select WHSID,WHSLOCATION from IVR_WAREHOUSE";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            ddlfromLoacation.DataSource = DT;
            ddlfromLoacation.DataTextField = "WHSLOCATION";
            ddlfromLoacation.DataValueField = "WHSID";
            ddlfromLoacation.DataBind();
            ddlfromLoacation.Items.Insert(0, new ListItem("-Select location-", "0"));

            ddlToLoacation.DataSource = DT;
            ddlToLoacation.DataTextField = "WHSLOCATION";
            ddlToLoacation.DataValueField = "WHSID";
            ddlToLoacation.DataBind();
            ddlToLoacation.Items.Insert(0, new ListItem("-Select location-", "0"));
        }
    }
    #endregion

    #region physical Primary Function
    protected void physical_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void physical_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(16);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_physical.Rows[rowno].FindControl("txtphysicalunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_physical.Rows[rowno].FindControl("hidphysicaluomid" + rowno.ToString());
        TextBox txtphysicalquantity = (TextBox)tbl_physical.Rows[rowno].FindControl("txtphysicalquantity" + rowno.ToString());
        TextBox txtphysicalrate = (TextBox)tbl_physical.Rows[rowno].FindControl("txtphysicalrate" + rowno.ToString());
        TextBox txtphysicalamount = (TextBox)tbl_physical.Rows[rowno].FindControl("txtphysicalamount" + rowno.ToString());
        TextBox txtphysicalreason = (TextBox)tbl_physical.Rows[rowno].FindControl("txtphysicalreason" + rowno.ToString());
        HiddenField hidphysicalLocation =(HiddenField) tbl_physical.Rows[rowno].FindControl("hidphysicalLocation" + rowno.ToString());

        txtphysicalquantity.Text = string.Empty;
        txtphysicalrate.Text = string.Empty;
        txtphysicalamount.Text = string.Empty;
        txtphysicalreason.Text = string.Empty;
        hidphysicalLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            physical_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void physical_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidphysicalCount.Value);
        for (int i = 1; i <= intCount; i++)
        {
            DropDownList ddlitems = (DropDownList)tbl_physical.Rows[i].FindControl("ddlphysicalitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_physical.Rows[i].FindControl("btnphysicalqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }
    #endregion

    #region production Primary Function
    protected void production_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void production_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(18);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_production.Rows[rowno].FindControl("txtproductionunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_production.Rows[rowno].FindControl("hidproductionuomid" + rowno.ToString());
        TextBox txtproductionquantity = (TextBox)tbl_production.Rows[rowno].FindControl("txtproductionquantity" + rowno.ToString());
        TextBox txtproductionrate = (TextBox)tbl_production.Rows[rowno].FindControl("txtproductionrate" + rowno.ToString());
        TextBox txtproductionamount = (TextBox)tbl_production.Rows[rowno].FindControl("txtproductionamount" + rowno.ToString());
        HiddenField hidproductionLocation = (HiddenField)tbl_production.Rows[rowno].FindControl("hidproductionLocation" + rowno.ToString());

        txtproductionquantity.Text = string.Empty;
        txtproductionrate.Text = string.Empty;
        txtproductionamount.Text = string.Empty;
        hidproductionLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            production_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void production_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidproductionCount.Value);
        for (int i = 1; i <= intCount; i++)
        {

            DropDownList ddlitems = (DropDownList)tbl_production.Rows[i].FindControl("ddlproductionitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_production.Rows[i].FindControl("txtproductionquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_production.Rows[i].FindControl("btnproductionqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }
    #endregion

    #region input jounal Primary Function
    protected void input_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void input_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(13);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_input.Rows[rowno].FindControl("txtinputunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_input.Rows[rowno].FindControl("hidinputuomid" + rowno.ToString());
        DropDownList ddlinputitems = (DropDownList)tbl_input.Rows[rowno].FindControl("ddlinputitems" + rowno.ToString());
        HiddenField hidinputuomid = (HiddenField)tbl_input.Rows[rowno].FindControl("hidinputuomid" + rowno.ToString());
        TextBox txtinputquantity = (TextBox)tbl_input.Rows[rowno].FindControl("txtinputquantity" + rowno.ToString());
        TextBox txtinputrate = (TextBox)tbl_input.Rows[rowno].FindControl("txtinputrate" + rowno.ToString());
        TextBox txtinputamount = (TextBox)tbl_input.Rows[rowno].FindControl("txtinputamount" + rowno.ToString());
        HiddenField hidinputLocation = (HiddenField)tbl_input.Rows[rowno].FindControl("hidinputLocation" + rowno.ToString());
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        txtinputquantity.Text = string.Empty;
        txtinputrate.Text = string.Empty;
        txtinputamount.Text = string.Empty;
        hidinputLocation.Value = string.Empty;

        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            input_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void input_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidinputCount.Value);
        for (int i = 1; i <= intCount; i++)
        {

            DropDownList ddlitems = (DropDownList)tbl_input.Rows[i].FindControl("ddlinputitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_input.Rows[i].FindControl("txtinputquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_input.Rows[i].FindControl("hidinputLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_input.Rows[i].FindControl("btninputqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }
    #endregion

    #region output jounal Primary Function
    protected void output_binditem(DropDownList ddl)
    {
        DataTable dtitem = DU.getdatausingprocedure("usp_ivr_get_all_item");
        if (dtitem.Rows.Count > 0)
        {
            ddl.DataSource = dtitem;
            ddl.DataTextField = "ITMDESC";
            ddl.DataValueField = "ITMID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("--- Select Items ---", "0"));
        }
    }
    protected void output_ddlitems_OnSelectedIndexChanged(Object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        string ddlid = ddl.ID.ToString().Substring(14);
        int rowno = Convert.ToInt32(ddlid.ToString());
        TextBox txtunit = (TextBox)tbl_output.Rows[rowno].FindControl("txtoutputunit" + rowno.ToString());
        HiddenField huono = (HiddenField)tbl_output.Rows[rowno].FindControl("hidoutputuomid" + rowno.ToString());
        TextBox txtoutputquantity = (TextBox)tbl_output.Rows[rowno].FindControl("txtoutputquantity" + rowno.ToString());
        TextBox txtoutputrate = (TextBox)tbl_output.Rows[rowno].FindControl("txtoutputrate" + rowno.ToString());
        TextBox txtoutputamount = (TextBox)tbl_output.Rows[rowno].FindControl("txtoutputamount" + rowno.ToString());
        HiddenField hidoutputLocation = (HiddenField)tbl_output.Rows[rowno].FindControl("hidoutputLocation" + rowno.ToString());

        txtoutputquantity.Text = string.Empty;
        txtoutputrate.Text = string.Empty;
        txtoutputamount.Text = string.Empty;
        hidoutputLocation.Value = string.Empty;
        txtunit.Text = string.Empty;
        huono.Value = string.Empty;
        if (ddl.SelectedValue != "0")
        {
            SqlParameter[] parr = { 
                              new SqlParameter("@itemid",ddl.SelectedValue)
                              };
            DataTable dtuom = DU.getdatausingprocedure("usp_ivr_get_uom_by_itemid", parr);

            txtunit.Text = dtuom.Rows[0]["UOMNAME"].ToString();
            huono.Value = dtuom.Rows[0]["UOMID"].ToString();

            output_BindJavaScriptItemQtyPopUp();
        }
        else
        {
            txtunit.Text = "";
            huono.Value = "";
        }
    }
    protected void output_BindJavaScriptItemQtyPopUp()
    {
        int intCount = Convert.ToInt32(hidoutputCount.Value);
        for (int i = 1; i <= intCount; i++)
        {

            DropDownList ddlitems = (DropDownList)tbl_output.Rows[i].FindControl("ddloutputitems" + i.ToString());
            TextBox txtquantity = (TextBox)tbl_output.Rows[i].FindControl("txtoutputquantity" + i.ToString());
            HiddenField hidLocationBillLevel = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputLocation" + i.ToString());
            Button btnQtyBillLevel = (Button)tbl_output.Rows[i].FindControl("btnoutputqty" + i.ToString());
            btnQtyBillLevel.Attributes.Add("onclick", "return GetQuantity('" + ddlitems.ClientID.ToString() + "', '" + txtquantity.ClientID.ToString() + "', '" + hidLocationBillLevel.ClientID.ToString() + "');");
        }
    }
    #endregion

    #region ADD MORE issue
    protected void issue_ADDMORE(string TableSource)
    {
        issueCounter++;
        listissuecounter.Add(issueCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddlissueitems = new DropDownList();
        ddlissueitems.ID = "ddl" + TableSource + "items" + issueCounter.ToString();
        ddlissueitems.CssClass = "dropdown";
        ddlissueitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
               // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        Issue_binditem(ddlissueitems);
        ddlissueitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'"+TableSource+"');");
        ddlissueitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddlissueitems.SelectedIndexChanged += new EventHandler(issue_ddlitems_OnSelectedIndexChanged);

        listddlissueitems.Add(ddlissueitems.ID);

        HiddenField hidissuesjiid = new HiddenField();
        hidissuesjiid.ID = "hid" + TableSource + "sjiid" + issueCounter.ToString();
        listhidissuesjiid.Add(hidissuesjiid.ID);

        HiddenField hidissuesidid = new HiddenField();
        hidissuesidid.ID = "hid" + TableSource + "sidid" + issueCounter.ToString();
        listhidissuesidid.Add(hidissuesidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txtissueunit = new TextBox();
        txtissueunit.ID = "txt" + TableSource + "unit" + issueCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtissueunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtissueunit.CssClass = "DisableInput";

        listtxtissueunit.Add(txtissueunit.ID);

        HiddenField hidissueuomid = new HiddenField();
        hidissueuomid.ID = "hid" + TableSource + "uomid" + issueCounter.ToString();
        listhidissueuomid.Add(hidissueuomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txtissuequantity = new TextBox();
        txtissuequantity.ID = "txt" + TableSource + "quantity" + issueCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtissuequantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtissuequantity.CssClass = "DisableInputNumber";

        listtxtissuequantity.Add(txtissuequantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnissueqty = new Button();
        btnissueqty.ID = "btn" + TableSource + "qty" + issueCounter.ToString();
        btnissueqty.CssClass = "button";
        btnissueqty.Width = Unit.Percentage(5);
        btnissueqty.Text = "...";

        listbtnissueqty.Add(btnissueqty.ID);

        HiddenField hidissueLocation = new HiddenField();
        hidissueLocation.ID = "hid" + TableSource + "Location" + issueCounter.ToString();

        listhidissueLocation.Add(hidissueLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txtissuerate = new TextBox();
        txtissuerate.ID = "txt" + TableSource + "rate" + issueCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtissuerate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtissuerate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('issue');");
        txtissuerate.CssClass = "inputnumber";

        listtxtissuerate.Add(txtissuerate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txtissueamount = new TextBox();
        txtissueamount.ID = "txt" + TableSource + "amount" + issueCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtissueamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtissueamount.CssClass = "DisableInputNumber";

        listtxtissueamount.Add(txtissueamount.ID);

        cell1.Controls.Add(ddlissueitems);
        cell1.Controls.Add(hidissuesjiid);
        cell1.Controls.Add(hidissuesidid);
        cell2.Controls.Add(txtissueunit);
        cell2.Controls.Add(hidissueuomid);
        cell3.Controls.Add(txtissuequantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnissueqty);
        cell3.Controls.Add(hidissueLocation);
        cell4.Controls.Add(txtissuerate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtissueamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_issue.Rows.Add(row1);
        hidissueCount.Value = issueCounter.ToString();
        
        ViewState["listissuecounter"] = listissuecounter;
        ViewState["listddlissueitems"] = listddlissueitems;
        ViewState["listhidissuesjiid"] = listhidissuesjiid;
        ViewState["listhidissuesidid"] = listhidissuesidid;
        ViewState["listtxtissueunit"] = listtxtissueunit;
        ViewState["listhidissueuomid"] = listhidissueuomid;
        ViewState["listtxtissuequantity"] = listtxtissuequantity;
        ViewState["listbtnissueqty"] = listbtnissueqty;
        ViewState["listhidissueLocation"] = listhidissueLocation;
        ViewState["listtxtissuerate"] = listtxtissuerate;
        ViewState["listtxtissueamount"] = listtxtissueamount;
    }
    protected void overrideissueaddmore(string TableSource)
    {
        listissuecounter = (List<string>)ViewState["listissuecounter"];
        listddlissueitems = (List<string>)ViewState["listddlissueitems"];
        listhidissuesjiid = (List<string>)ViewState["listhidissuesjiid"];
        listhidissuesidid = (List<string>)ViewState["listhidissuesidid"];
        listtxtissueunit = (List<string>)ViewState["listtxtissueunit"];
        listhidissueuomid = (List<string>)ViewState["listhidissueuomid"];
        listtxtissuequantity = (List<string>)ViewState["listtxtissuequantity"];
        listbtnissueqty = (List<string>)ViewState["listbtnissueqty"];
        listhidissueLocation = (List<string>)ViewState["listhidissueLocation"];
        listtxtissuerate = (List<string>)ViewState["listtxtissuerate"];
        listtxtissueamount = (List<string>)ViewState["listtxtissueamount"];

        if (listissuecounter != null)
        {
            int tempccounter = Convert.ToInt32(listissuecounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                issueCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddlissueitems = new DropDownList();
                ddlissueitems.ID = listddlissueitems[i].ToString();
                ddlissueitems.CssClass = "dropdown";
                ddlissueitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                Issue_binditem(ddlissueitems);
                ddlissueitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddlissueitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddlissueitems.SelectedIndexChanged += new EventHandler(issue_ddlitems_OnSelectedIndexChanged);

                HiddenField hidissuesjiid = new HiddenField();
                hidissuesjiid.ID = listhidissuesjiid[i].ToString();

                HiddenField hidissuesidid = new HiddenField();
                hidissuesidid.ID = listhidissuesidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txtissueunit = new TextBox();
                txtissueunit.ID = listtxtissueunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtissueunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtissueunit.CssClass = "DisableInput";


                HiddenField hidissueuomid = new HiddenField();
                hidissueuomid.ID = listhidissueuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txtissuequantity = new TextBox();
                txtissuequantity.ID = listtxtissuequantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtissuequantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtissuequantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnissueqty = new Button();
                btnissueqty.ID = listbtnissueqty[i].ToString();
                btnissueqty.CssClass = "button";
                btnissueqty.Width = Unit.Percentage(5);
                btnissueqty.Text = "...";

                HiddenField hidissueLocation = new HiddenField();
                hidissueLocation.ID = listhidissueLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txtissuerate = new TextBox();
                txtissuerate.ID = listtxtissuerate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtissuerate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtissuerate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('issue');");
                txtissuerate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txtissueamount = new TextBox();
                txtissueamount.ID = listtxtissueamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtissueamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtissueamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddlissueitems);
                cell2.Controls.Add(txtissueunit);
                cell2.Controls.Add(hidissueuomid);
                cell3.Controls.Add(txtissuequantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnissueqty);
                cell3.Controls.Add(hidissueLocation);
                cell4.Controls.Add(txtissuerate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtissueamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_issue.Rows.Add(row1);
            }
        }
    }
    #endregion
    protected void btnissueaddmore_Click(object sender, EventArgs e)
    {
        issue_ADDMORE("issue");
        Issue_BindJavaScriptItemQtyPopUp();
        
    }
    #region ADD MORE recieved
    protected void recieved_ADDMORE(string TableSource)
    {
        recievedCounter++;
        listrecievedcounter.Add(recievedCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddlrecieveditems = new DropDownList();
        ddlrecieveditems.ID = "ddl" + TableSource + "items" + recievedCounter.ToString();
        ddlrecieveditems.CssClass = "dropdown";
        //ddlrecieveditems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        recieved_binditem(ddlrecieveditems);
        ddlrecieveditems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
        ddlrecieveditems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddlrecieveditems.SelectedIndexChanged += new EventHandler(recieved_ddlitems_OnSelectedIndexChanged);

        listddlrecieveditems.Add(ddlrecieveditems.ID);

        HiddenField hidrecievedsjiid = new HiddenField();
        hidrecievedsjiid.ID = "hid" + TableSource + "sjiid" + recievedCounter.ToString();
        listhidrecievedsjiid.Add(hidrecievedsjiid.ID);

        HiddenField hidrecievedsidid = new HiddenField();
        hidrecievedsidid.ID = "hid" + TableSource + "sidid" + recievedCounter.ToString();
        listhidrecievedsidid.Add(hidrecievedsidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txtrecievedunit = new TextBox();
        txtrecievedunit.ID = "txt" + TableSource + "unit" + recievedCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtrecievedunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtrecievedunit.CssClass = "DisableInput";

        listtxtrecievedunit.Add(txtrecievedunit.ID);

        HiddenField hidrecieveduomid = new HiddenField();
        hidrecieveduomid.ID = "hid" + TableSource + "uomid" + recievedCounter.ToString();
        listhidrecieveduomid.Add(hidrecieveduomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txtrecievedquantity = new TextBox();
        txtrecievedquantity.ID = "txt" + TableSource + "quantity" + recievedCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtrecievedquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtrecievedquantity.CssClass = "DisableInputNumber";

        listtxtrecievedquantity.Add(txtrecievedquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnrecievedqty = new Button();
        btnrecievedqty.ID = "btn" + TableSource + "qty" + recievedCounter.ToString();
        btnrecievedqty.CssClass = "button";
        btnrecievedqty.Width = Unit.Percentage(5);
        btnrecievedqty.Text = "...";

        listbtnrecievedqty.Add(btnrecievedqty.ID);

        HiddenField hidrecievedLocation = new HiddenField();
        hidrecievedLocation.ID = "hid" + TableSource + "Location" + recievedCounter.ToString();

        listhidrecievedLocation.Add(hidrecievedLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txtrecievedrate = new TextBox();
        txtrecievedrate.ID = "txt" + TableSource + "rate" + recievedCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtrecievedrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtrecievedrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('recieved');");
        txtrecievedrate.CssClass = "inputnumber";

        listtxtrecievedrate.Add(txtrecievedrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txtrecievedamount = new TextBox();
        txtrecievedamount.ID = "txt" + TableSource + "amount" + recievedCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtrecievedamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtrecievedamount.CssClass = "DisableInputNumber";

        listtxtrecievedamount.Add(txtrecievedamount.ID);

        cell1.Controls.Add(ddlrecieveditems);
        cell1.Controls.Add(hidrecievedsjiid);
        cell1.Controls.Add(hidrecievedsidid);
        cell2.Controls.Add(txtrecievedunit);
        cell2.Controls.Add(hidrecieveduomid);
        cell3.Controls.Add(txtrecievedquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnrecievedqty);
        cell3.Controls.Add(hidrecievedLocation);
        cell4.Controls.Add(txtrecievedrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtrecievedamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_recieved.Rows.Add(row1);
        hidrecievedCount.Value = recievedCounter.ToString();

        ViewState["listrecievedcounter"] = listrecievedcounter;
        ViewState["listddlrecieveditems"] = listddlrecieveditems;
        ViewState["listhidrecievedsjiid"] = listhidrecievedsjiid;
        ViewState["listhidrecievedsidid"] = listhidrecievedsidid;
        ViewState["listtxtrecievedunit"] = listtxtrecievedunit;
        ViewState["listhidrecieveduomid"] = listhidrecieveduomid;
        ViewState["listtxtrecievedquantity"] = listtxtrecievedquantity;
        ViewState["listbtnrecievedqty"] = listbtnrecievedqty;
        ViewState["listhidrecievedLocation"] = listhidrecievedLocation;
        ViewState["listtxtrecievedrate"] = listtxtrecievedrate;
        ViewState["listtxtrecievedamount"] = listtxtrecievedamount;
    }
    protected void overriderecievedaddmore(string TableSource)
    {
        listrecievedcounter = (List<string>)ViewState["listrecievedcounter"];
        listddlrecieveditems = (List<string>)ViewState["listddlrecieveditems"];
        listhidrecievedsjiid = (List<string>)ViewState["listhidrecievedsjiid"];
        listhidrecievedsidid = (List<string>)ViewState["listhidrecievedsidid"];
        listtxtrecievedunit = (List<string>)ViewState["listtxtrecievedunit"];
        listhidrecieveduomid = (List<string>)ViewState["listhidrecieveduomid"];
        listtxtrecievedquantity = (List<string>)ViewState["listtxtrecievedquantity"];
        listbtnrecievedqty = (List<string>)ViewState["listbtnrecievedqty"];
        listhidrecievedLocation = (List<string>)ViewState["listhidrecievedLocation"];
        listtxtrecievedrate = (List<string>)ViewState["listtxtrecievedrate"];
        listtxtrecievedamount = (List<string>)ViewState["listtxtrecievedamount"];

        if (listrecievedcounter != null)
        {
            int tempccounter = Convert.ToInt32(listrecievedcounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                recievedCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddlrecieveditems = new DropDownList();
                ddlrecieveditems.ID = listddlrecieveditems[i].ToString();
                ddlrecieveditems.CssClass = "dropdown";
                //ddlrecieveditems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                recieved_binditem(ddlrecieveditems);
                ddlrecieveditems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddlrecieveditems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddlrecieveditems.SelectedIndexChanged += new EventHandler(recieved_ddlitems_OnSelectedIndexChanged);

                HiddenField hidrecievedsjiid = new HiddenField();
                hidrecievedsjiid.ID = listhidrecievedsjiid[i].ToString();

                HiddenField hidrecievedsidid = new HiddenField();
                hidrecievedsidid.ID = listhidrecievedsidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txtrecievedunit = new TextBox();
                txtrecievedunit.ID = listtxtrecievedunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtrecievedunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtrecievedunit.CssClass = "DisableInput";


                HiddenField hidrecieveduomid = new HiddenField();
                hidrecieveduomid.ID = listhidrecieveduomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txtrecievedquantity = new TextBox();
                txtrecievedquantity.ID = listtxtrecievedquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtrecievedquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtrecievedquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnrecievedqty = new Button();
                btnrecievedqty.ID = listbtnrecievedqty[i].ToString();
                btnrecievedqty.CssClass = "button";
                btnrecievedqty.Width = Unit.Percentage(5);
                btnrecievedqty.Text = "...";

                HiddenField hidrecievedLocation = new HiddenField();
                hidrecievedLocation.ID = listhidrecievedLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txtrecievedrate = new TextBox();
                txtrecievedrate.ID = listtxtrecievedrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtrecievedrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtrecievedrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('recieved');");
                txtrecievedrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txtrecievedamount = new TextBox();
                txtrecievedamount.ID = listtxtrecievedamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtrecievedamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtrecievedamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddlrecieveditems);
                cell1.Controls.Add(hidrecievedsjiid);
                cell1.Controls.Add(hidrecievedsidid);
                cell2.Controls.Add(txtrecievedunit);
                cell2.Controls.Add(hidrecieveduomid);
                cell3.Controls.Add(txtrecievedquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnrecievedqty);
                cell3.Controls.Add(hidrecievedLocation);
                cell4.Controls.Add(txtrecievedrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtrecievedamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_recieved.Rows.Add(row1);
            }
        }
    }
    #endregion
    protected void btnrecievedaddmore_Click(object sender, EventArgs e)
    {
        recieved_ADDMORE("recieved");
        recieved_BindJavaScriptItemQtyPopUp();
    }
    #region ADD MORE transfer
    protected void transfer_ADDMORE(string TableSource)
    {
        transferCounter++;
        listtransfercounter.Add(transferCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddltransferitems = new DropDownList();
        ddltransferitems.ID = "ddl" + TableSource + "items" + transferCounter.ToString();
        ddltransferitems.CssClass = "dropdown";
        //ddltransferitems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        transfer_binditem(ddltransferitems);
        ddltransferitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
        ddltransferitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddltransferitems.SelectedIndexChanged += new EventHandler(transfer_ddlitems_OnSelectedIndexChanged);

        listddltransferitems.Add(ddltransferitems.ID);

        HiddenField hidtransfersjiid = new HiddenField();
        hidtransfersjiid.ID = "hid" + TableSource + "sjiid" + transferCounter.ToString();
        listhidtransfersjiid.Add(hidtransfersjiid.ID);

        HiddenField hidtransfersidid = new HiddenField();
        hidtransfersidid.ID = "hid" + TableSource + "sidid" + transferCounter.ToString();
        listhidtransfersidid.Add(hidtransfersidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txttransferunit = new TextBox();
        txttransferunit.ID = "txt" + TableSource + "unit" + transferCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txttransferunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txttransferunit.CssClass = "DisableInput";

        listtxttransferunit.Add(txttransferunit.ID);

        HiddenField hidtransferuomid = new HiddenField();
        hidtransferuomid.ID = "hid" + TableSource + "uomid" + transferCounter.ToString();
        listhidtransferuomid.Add(hidtransferuomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txttransferquantity = new TextBox();
        txttransferquantity.ID = "txt" + TableSource + "quantity" + transferCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txttransferquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txttransferquantity.CssClass = "DisableInputNumber";

        listtxttransferquantity.Add(txttransferquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btntransferqty = new Button();
        btntransferqty.ID = "btn" + TableSource + "qty" + transferCounter.ToString();
        btntransferqty.CssClass = "button";
        btntransferqty.Width = Unit.Percentage(5);
        btntransferqty.Text = "...";

        listbtntransferqty.Add(btntransferqty.ID);

        HiddenField hidtransferLocation = new HiddenField();
        hidtransferLocation.ID = "hid" + TableSource + "Location" + transferCounter.ToString();

        listhidtransferLocation.Add(hidtransferLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txttransferrate = new TextBox();
        txttransferrate.ID = "txt" + TableSource + "rate" + transferCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txttransferrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txttransferrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('transfer');");
        txttransferrate.CssClass = "inputnumber";

        listtxttransferrate.Add(txttransferrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txttransferamount = new TextBox();
        txttransferamount.ID = "txt" + TableSource + "amount" + transferCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txttransferamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txttransferamount.CssClass = "DisableInputNumber";

        listtxttransferamount.Add(txttransferamount.ID);

        cell1.Controls.Add(ddltransferitems);
        cell1.Controls.Add(hidtransfersjiid);
        cell1.Controls.Add(hidtransfersidid);
        cell2.Controls.Add(txttransferunit);
        cell2.Controls.Add(hidtransferuomid);
        cell3.Controls.Add(txttransferquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btntransferqty);
        cell3.Controls.Add(hidtransferLocation);
        cell4.Controls.Add(txttransferrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txttransferamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_transfer.Rows.Add(row1);
        hidtransferCount.Value = transferCounter.ToString();

        ViewState["listtransfercounter"] = listtransfercounter;
        ViewState["listddltransferitems"] = listddltransferitems;
        ViewState["listhidtransfersjiid"] = listhidtransfersjiid;
        ViewState["listhidtransfersidid"] = listhidtransfersidid;
        ViewState["listtxttransferunit"] = listtxttransferunit;
        ViewState["listhidtransferuomid"] = listhidtransferuomid;
        ViewState["listtxttransferquantity"] = listtxttransferquantity;
        ViewState["listbtntransferqty"] = listbtntransferqty;
        ViewState["listhidtransferLocation"] = listhidtransferLocation;
        ViewState["listtxttransferrate"] = listtxttransferrate;
        ViewState["listtxttransferamount"] = listtxttransferamount;
    }
    protected void overridetransferaddmore(string TableSource)
    {
        listtransfercounter = (List<string>)ViewState["listtransfercounter"];
        listddltransferitems = (List<string>)ViewState["listddltransferitems"];
        listhidtransfersjiid = (List<string>)ViewState["listhidtransfersjiid"];
        listhidtransfersidid = (List<string>)ViewState["listhidtransfersidid"];
        listtxttransferunit = (List<string>)ViewState["listtxttransferunit"];
        listhidtransferuomid = (List<string>)ViewState["listhidtransferuomid"];
        listtxttransferquantity = (List<string>)ViewState["listtxttransferquantity"];
        listbtntransferqty = (List<string>)ViewState["listbtntransferqty"];
        listhidtransferLocation = (List<string>)ViewState["listhidtransferLocation"];
        listtxttransferrate = (List<string>)ViewState["listtxttransferrate"];
        listtxttransferamount = (List<string>)ViewState["listtxttransferamount"];

        if (listtransfercounter != null)
        {
            int tempccounter = Convert.ToInt32(listtransfercounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                transferCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddltransferitems = new DropDownList();
                ddltransferitems.ID = listddltransferitems[i].ToString();
                ddltransferitems.CssClass = "dropdown";
                //ddltransferitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                transfer_binditem(ddltransferitems);
                ddltransferitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddltransferitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddltransferitems.SelectedIndexChanged += new EventHandler(transfer_ddlitems_OnSelectedIndexChanged);

                HiddenField hidtransfersjiid = new HiddenField();
                hidtransfersjiid.ID = listhidtransfersjiid[i].ToString();

                HiddenField hidtransfersidid = new HiddenField();
                hidtransfersidid.ID = listhidtransfersidid[i].ToString();
               

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txttransferunit = new TextBox();
                txttransferunit.ID = listtxttransferunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txttransferunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txttransferunit.CssClass = "DisableInput";


                HiddenField hidtransferuomid = new HiddenField();
                hidtransferuomid.ID = listhidtransferuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txttransferquantity = new TextBox();
                txttransferquantity.ID = listtxttransferquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txttransferquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txttransferquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btntransferqty = new Button();
                btntransferqty.ID = listbtntransferqty[i].ToString();
                btntransferqty.CssClass = "button";
                btntransferqty.Width = Unit.Percentage(5);
                btntransferqty.Text = "...";

                HiddenField hidtransferLocation = new HiddenField();
                hidtransferLocation.ID = listhidtransferLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txttransferrate = new TextBox();
                txttransferrate.ID = listtxttransferrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txttransferrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txttransferrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('transfer');");
                txttransferrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txttransferamount = new TextBox();
                txttransferamount.ID = listtxttransferamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txttransferamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txttransferamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddltransferitems);
                cell1.Controls.Add(hidtransfersjiid);
                cell1.Controls.Add(hidtransfersidid);
                cell2.Controls.Add(txttransferunit);
                cell2.Controls.Add(hidtransferuomid);
                cell3.Controls.Add(txttransferquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btntransferqty);
                cell3.Controls.Add(hidtransferLocation);
                cell4.Controls.Add(txttransferrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txttransferamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_transfer.Rows.Add(row1);
            }
        }
    }
    #endregion ADD MORE transfer
    protected void btntransferaddmore_Click(object sender, EventArgs e)
    {
        transfer_ADDMORE("transfer");
        transfer_BindJavaScriptItemQtyPopUp();
    }
    #region ADD MORE input
    protected void input_ADDMORE(string TableSource)
    {
        inputCounter++;
        listinputcounter.Add(inputCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddlinputitems = new DropDownList();
        ddlinputitems.ID = "ddl" + TableSource + "items" + inputCounter.ToString();
        ddlinputitems.CssClass = "dropdown";
        //ddlinputitems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        input_binditem(ddlinputitems);
        ddlinputitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
        ddlinputitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddlinputitems.SelectedIndexChanged += new EventHandler(input_ddlitems_OnSelectedIndexChanged);

        listddlinputitems.Add(ddlinputitems.ID);

        HiddenField hidinputsjiid = new HiddenField();
        hidinputsjiid.ID = "hid" + TableSource + "sjiid" + inputCounter.ToString();
        listhidinputsjiid.Add(hidinputsjiid.ID);

        HiddenField hidinputsidid = new HiddenField();
        hidinputsidid.ID = "hid" + TableSource + "sidid" + inputCounter.ToString();
        listhidinputsidid.Add(hidinputsidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txtinputunit = new TextBox();
        txtinputunit.ID = "txt" + TableSource + "unit" + inputCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtinputunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtinputunit.CssClass = "DisableInput";

        listtxtinputunit.Add(txtinputunit.ID);

        HiddenField hidinputuomid = new HiddenField();
        hidinputuomid.ID = "hid" + TableSource + "uomid" + inputCounter.ToString();
        listhidinputuomid.Add(hidinputuomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txtinputquantity = new TextBox();
        txtinputquantity.ID = "txt" + TableSource + "quantity" + inputCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtinputquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtinputquantity.CssClass = "DisableInputNumber";

        listtxtinputquantity.Add(txtinputquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btninputqty = new Button();
        btninputqty.ID = "btn" + TableSource + "qty" + inputCounter.ToString();
        btninputqty.CssClass = "button";
        btninputqty.Width = Unit.Percentage(5);
        btninputqty.Text = "...";

        listbtninputqty.Add(btninputqty.ID);

        HiddenField hidinputLocation = new HiddenField();
        hidinputLocation.ID = "hid" + TableSource + "Location" + inputCounter.ToString();

        listhidinputLocation.Add(hidinputLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txtinputrate = new TextBox();
        txtinputrate.ID = "txt" + TableSource + "rate" + inputCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtinputrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtinputrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('input');");
        txtinputrate.CssClass = "inputnumber";

        listtxtinputrate.Add(txtinputrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txtinputamount = new TextBox();
        txtinputamount.ID = "txt" + TableSource + "amount" + inputCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtinputamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtinputamount.CssClass = "DisableInputNumber";

        listtxtinputamount.Add(txtinputamount.ID);

        cell1.Controls.Add(ddlinputitems);
        cell1.Controls.Add(hidinputsjiid);
        cell1.Controls.Add(hidinputsidid);
        cell2.Controls.Add(txtinputunit);
        cell2.Controls.Add(hidinputuomid);
        cell3.Controls.Add(txtinputquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btninputqty);
        cell3.Controls.Add(hidinputLocation);
        cell4.Controls.Add(txtinputrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtinputamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_input.Rows.Add(row1);
        hidinputCount.Value = inputCounter.ToString();

        ViewState["listinputcounter"] = listinputcounter;
        ViewState["listddlinputitems"] = listddlinputitems;
        ViewState["listhidinputsjiid"] = listhidinputsjiid;
        ViewState["listhidinputsidid"] = listhidinputsidid;
        ViewState["listtxtinputunit"] = listtxtinputunit;
        ViewState["listhidinputuomid"] = listhidinputuomid;
        ViewState["listtxtinputquantity"] = listtxtinputquantity;
        ViewState["listbtninputqty"] = listbtninputqty;
        ViewState["listhidinputLocation"] = listhidinputLocation;
        ViewState["listtxtinputrate"] = listtxtinputrate;
        ViewState["listtxtinputamount"] = listtxtinputamount;
    }
    protected void overrideinputaddmore(string TableSource)
    {
        listinputcounter = (List<string>)ViewState["listinputcounter"];
        listddlinputitems = (List<string>)ViewState["listddlinputitems"];
        listhidinputsjiid = (List<string>)ViewState["listhidinputsjiid"];
        listhidinputsidid = (List<string>)ViewState["listhidinputsidid"];
        listtxtinputunit = (List<string>)ViewState["listtxtinputunit"];
        listhidinputuomid = (List<string>)ViewState["listhidinputuomid"];
        listtxtinputquantity = (List<string>)ViewState["listtxtinputquantity"];
        listbtninputqty = (List<string>)ViewState["listbtninputqty"];
        listhidinputLocation = (List<string>)ViewState["listhidinputLocation"];
        listtxtinputrate = (List<string>)ViewState["listtxtinputrate"];
        listtxtinputamount = (List<string>)ViewState["listtxtinputamount"];

        if (listinputcounter != null)
        {
            int tempccounter = Convert.ToInt32(listinputcounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                inputCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddlinputitems = new DropDownList();
                ddlinputitems.ID = listddlinputitems[i].ToString();
                ddlinputitems.CssClass = "dropdown";
                //ddlinputitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                input_binditem(ddlinputitems);
                ddlinputitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddlinputitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddlinputitems.SelectedIndexChanged += new EventHandler(input_ddlitems_OnSelectedIndexChanged);

                HiddenField hidinputsjiid = new HiddenField();
                hidinputsjiid.ID = listhidinputsjiid[i].ToString();
               
                HiddenField hidinputsidid = new HiddenField();
                hidinputsidid.ID = listhidinputsidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txtinputunit = new TextBox();
                txtinputunit.ID = listtxtinputunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtinputunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtinputunit.CssClass = "DisableInput";


                HiddenField hidinputuomid = new HiddenField();
                hidinputuomid.ID = listhidinputuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txtinputquantity = new TextBox();
                txtinputquantity.ID = listtxtinputquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtinputquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtinputquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btninputqty = new Button();
                btninputqty.ID = listbtninputqty[i].ToString();
                btninputqty.CssClass = "button";
                btninputqty.Width = Unit.Percentage(5);
                btninputqty.Text = "...";

                HiddenField hidinputLocation = new HiddenField();
                hidinputLocation.ID = listhidinputLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txtinputrate = new TextBox();
                txtinputrate.ID = listtxtinputrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtinputrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtinputrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('input');");
                txtinputrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txtinputamount = new TextBox();
                txtinputamount.ID = listtxtinputamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtinputamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtinputamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddlinputitems);
                cell1.Controls.Add(hidinputsjiid);
                cell1.Controls.Add(hidinputsidid);
                cell2.Controls.Add(txtinputunit);
                cell2.Controls.Add(hidinputuomid);
                cell3.Controls.Add(txtinputquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btninputqty);
                cell3.Controls.Add(hidinputLocation);
                cell4.Controls.Add(txtinputrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtinputamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_input.Rows.Add(row1);
            }
        }
    }
    #endregion ADD MORE input
    protected void btninputaddmore_Click(object sender, EventArgs e)
    {
        input_ADDMORE("input");
        input_BindJavaScriptItemQtyPopUp();
    }
    #region ADD MORE output
    protected void output_ADDMORE(string TableSource)
    {
        outputCounter++;
        listoutputcounter.Add(outputCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddloutputitems = new DropDownList();
        ddloutputitems.ID = "ddl" + TableSource + "items" + outputCounter.ToString();
        ddloutputitems.CssClass = "dropdown";
        //ddloutputitems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        output_binditem(ddloutputitems);
        ddloutputitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
        ddloutputitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddloutputitems.SelectedIndexChanged += new EventHandler(output_ddlitems_OnSelectedIndexChanged);

        listddloutputitems.Add(ddloutputitems.ID);

        HiddenField hidoutputsjiid = new HiddenField();
        hidoutputsjiid.ID = "hid" + TableSource + "sjiid" + outputCounter.ToString();
        listhidoutputsjiid.Add(hidoutputsjiid.ID);

        HiddenField hidoutputsidid = new HiddenField();
        hidoutputsidid.ID = "hid" + TableSource + "sidid" + outputCounter.ToString();
        listhidoutputsidid.Add(hidoutputsidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txtoutputunit = new TextBox();
        txtoutputunit.ID = "txt" + TableSource + "unit" + outputCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtoutputunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtoutputunit.CssClass = "DisableInput";

        listtxtoutputunit.Add(txtoutputunit.ID);

        HiddenField hidoutputuomid = new HiddenField();
        hidoutputuomid.ID = "hid" + TableSource + "uomid" + outputCounter.ToString();
        listhidoutputuomid.Add(hidoutputuomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txtoutputquantity = new TextBox();
        txtoutputquantity.ID = "txt" + TableSource + "quantity" + outputCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtoutputquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtoutputquantity.CssClass = "DisableInputNumber";

        listtxtoutputquantity.Add(txtoutputquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnoutputqty = new Button();
        btnoutputqty.ID = "btn" + TableSource + "qty" + outputCounter.ToString();
        btnoutputqty.CssClass = "button";
        btnoutputqty.Width = Unit.Percentage(5);
        btnoutputqty.Text = "...";

        listbtnoutputqty.Add(btnoutputqty.ID);

        HiddenField hidoutputLocation = new HiddenField();
        hidoutputLocation.ID = "hid" + TableSource + "Location" + outputCounter.ToString();

        listhidoutputLocation.Add(hidoutputLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txtoutputrate = new TextBox();
        txtoutputrate.ID = "txt" + TableSource + "rate" + outputCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtoutputrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtoutputrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('output');");
        txtoutputrate.CssClass = "inputnumber";

        listtxtoutputrate.Add(txtoutputrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txtoutputamount = new TextBox();
        txtoutputamount.ID = "txt" + TableSource + "amount" + outputCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtoutputamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtoutputamount.CssClass = "DisableInputNumber";

        listtxtoutputamount.Add(txtoutputamount.ID);

        cell1.Controls.Add(ddloutputitems);
        cell1.Controls.Add(hidoutputsjiid);
        cell1.Controls.Add(hidoutputsidid);
        cell2.Controls.Add(txtoutputunit);
        cell2.Controls.Add(hidoutputuomid);
        cell3.Controls.Add(txtoutputquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnoutputqty);
        cell3.Controls.Add(hidoutputLocation);
        cell4.Controls.Add(txtoutputrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtoutputamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_output.Rows.Add(row1);
        hidoutputCount.Value = outputCounter.ToString();

        ViewState["listoutputcounter"] = listoutputcounter;
        ViewState["listddloutputitems"] = listddloutputitems;
        ViewState["listhidoutputsjiid"] = listhidoutputsjiid;
        ViewState["listhidoutputsidid"] = listhidoutputsidid;
        ViewState["listtxtoutputunit"] = listtxtoutputunit;
        ViewState["listhidoutputuomid"] = listhidoutputuomid;
        ViewState["listtxtoutputquantity"] = listtxtoutputquantity;
        ViewState["listbtnoutputqty"] = listbtnoutputqty;
        ViewState["listhidoutputLocation"] = listhidoutputLocation;
        ViewState["listtxtoutputrate"] = listtxtoutputrate;
        ViewState["listtxtoutputamount"] = listtxtoutputamount;
    }
    protected void overrideoutputaddmore(string TableSource)
    {
        listoutputcounter = (List<string>)ViewState["listoutputcounter"];
        listddloutputitems = (List<string>)ViewState["listddloutputitems"];
        listhidoutputsjiid = (List<string>)ViewState["listhidoutputsjiid"];
        listhidoutputsidid = (List<string>)ViewState["listhidoutputsidid"];
        listtxtoutputunit = (List<string>)ViewState["listtxtoutputunit"];
        listhidoutputuomid = (List<string>)ViewState["listhidoutputuomid"];
        listtxtoutputquantity = (List<string>)ViewState["listtxtoutputquantity"];
        listbtnoutputqty = (List<string>)ViewState["listbtnoutputqty"];
        listhidoutputLocation = (List<string>)ViewState["listhidoutputLocation"];
        listtxtoutputrate = (List<string>)ViewState["listtxtoutputrate"];
        listtxtoutputamount = (List<string>)ViewState["listtxtoutputamount"];

        if (listoutputcounter != null)
        {
            int tempccounter = Convert.ToInt32(listoutputcounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                outputCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddloutputitems = new DropDownList();
                ddloutputitems.ID = listddloutputitems[i].ToString();
                ddloutputitems.CssClass = "dropdown";
                //ddloutputitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                output_binditem(ddloutputitems);
                ddloutputitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddloutputitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddloutputitems.SelectedIndexChanged += new EventHandler(output_ddlitems_OnSelectedIndexChanged);

                HiddenField hidoutputsjiid = new HiddenField();
                hidoutputsjiid.ID = listhidoutputsjiid[i].ToString();

                HiddenField hidoutputsidid = new HiddenField();
                hidoutputsidid.ID = listhidoutputsidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txtoutputunit = new TextBox();
                txtoutputunit.ID = listtxtoutputunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtoutputunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtoutputunit.CssClass = "DisableInput";


                HiddenField hidoutputuomid = new HiddenField();
                hidoutputuomid.ID = listhidoutputuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txtoutputquantity = new TextBox();
                txtoutputquantity.ID = listtxtoutputquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtoutputquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtoutputquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnoutputqty = new Button();
                btnoutputqty.ID = listbtnoutputqty[i].ToString();
                btnoutputqty.CssClass = "button";
                btnoutputqty.Width = Unit.Percentage(5);
                btnoutputqty.Text = "...";

                HiddenField hidoutputLocation = new HiddenField();
                hidoutputLocation.ID = listhidoutputLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txtoutputrate = new TextBox();
                txtoutputrate.ID = listtxtoutputrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtoutputrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtoutputrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('output');");
                txtoutputrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txtoutputamount = new TextBox();
                txtoutputamount.ID = listtxtoutputamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtoutputamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtoutputamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddloutputitems);
                cell1.Controls.Add(hidoutputsjiid);
                cell1.Controls.Add(hidoutputsidid);
                cell2.Controls.Add(txtoutputunit);
                cell2.Controls.Add(hidoutputuomid);
                cell3.Controls.Add(txtoutputquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnoutputqty);
                cell3.Controls.Add(hidoutputLocation);
                cell4.Controls.Add(txtoutputrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtoutputamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_output.Rows.Add(row1);
            }
        }
    }
    #endregion ADD MORE output
    protected void btnoutputaddmore_Click(object sender, EventArgs e)
    {
        output_ADDMORE("output");
        output_BindJavaScriptItemQtyPopUp();
    }
    #region ADD MORE production
    protected void production_ADDMORE(string TableSource)
    {
        productionCounter++;
        listproductioncounter.Add(productionCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "20%;");
        DropDownList ddlproductionitems = new DropDownList();
        ddlproductionitems.ID = "ddl" + TableSource + "items" + productionCounter.ToString();
        ddlproductionitems.CssClass = "dropdown";
        //ddlproductionitems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        production_binditem(ddlproductionitems);
        ddlproductionitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
        ddlproductionitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddlproductionitems.SelectedIndexChanged += new EventHandler(production_ddlitems_OnSelectedIndexChanged);

        listddlproductionitems.Add(ddlproductionitems.ID);

        HiddenField hidproductionsjiid = new HiddenField();
        hidproductionsjiid.ID = "hid" + TableSource + "sjiid" + productionCounter.ToString();
        listhidproductionsjiid.Add(hidproductionsjiid.ID);

        HiddenField hidproductionsidid = new HiddenField();
        hidproductionsidid.ID = "hid" + TableSource + "sidid" + productionCounter.ToString();
        listhidproductionsidid.Add(hidproductionsidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "20%;");
        TextBox txtproductionunit = new TextBox();
        txtproductionunit.ID = "txt" + TableSource + "unit" + productionCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtproductionunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtproductionunit.CssClass = "DisableInput";

        listtxtproductionunit.Add(txtproductionunit.ID);

        HiddenField hidproductionuomid = new HiddenField();
        hidproductionuomid.ID = "hid" + TableSource + "uomid" + productionCounter.ToString();
        listhidproductionuomid.Add(hidproductionuomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "20%;");
        TextBox txtproductionquantity = new TextBox();
        txtproductionquantity.ID = "txt" + TableSource + "quantity" + productionCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtproductionquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtproductionquantity.CssClass = "DisableInputNumber";

        listtxtproductionquantity.Add(txtproductionquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnproductionqty = new Button();
        btnproductionqty.ID = "btn" + TableSource + "qty" + productionCounter.ToString();
        btnproductionqty.CssClass = "button";
        btnproductionqty.Width = Unit.Percentage(5);
        btnproductionqty.Text = "...";

        listbtnproductionqty.Add(btnproductionqty.ID);

        HiddenField hidproductionLocation = new HiddenField();
        hidproductionLocation.ID = "hid" + TableSource + "Location" + productionCounter.ToString();

        listhidproductionLocation.Add(hidproductionLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "20%;");
        TextBox txtproductionrate = new TextBox();
        txtproductionrate.ID = "txt" + TableSource + "rate" + productionCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtproductionrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtproductionrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('production');");
        txtproductionrate.CssClass = "inputnumber";

        listtxtproductionrate.Add(txtproductionrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "20%;");
        TextBox txtproductionamount = new TextBox();
        txtproductionamount.ID = "txt" + TableSource + "amount" + productionCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtproductionamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtproductionamount.CssClass = "DisableInputNumber";

        listtxtproductionamount.Add(txtproductionamount.ID);

        cell1.Controls.Add(ddlproductionitems);
        cell1.Controls.Add(hidproductionsjiid);
        cell1.Controls.Add(hidproductionsidid);
        cell2.Controls.Add(txtproductionunit);
        cell2.Controls.Add(hidproductionuomid);
        cell3.Controls.Add(txtproductionquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnproductionqty);
        cell3.Controls.Add(hidproductionLocation);
        cell4.Controls.Add(txtproductionrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtproductionamount);
        //cell5.Controls.Add(hidtaxamt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_production.Rows.Add(row1);
        hidproductionCount.Value = productionCounter.ToString();

        ViewState["listproductioncounter"] = listproductioncounter;
        ViewState["listddlproductionitems"] = listddlproductionitems;
        ViewState["listhidproductionsjiid"] = listhidproductionsjiid;
        ViewState["listhidproductionsidid"] = listhidproductionsidid;
        ViewState["listtxtproductionunit"] = listtxtproductionunit;
        ViewState["listhidproductionuomid"] = listhidproductionuomid;
        ViewState["listtxtproductionquantity"] = listtxtproductionquantity;
        ViewState["listbtnproductionqty"] = listbtnproductionqty;
        ViewState["listhidproductionLocation"] = listhidproductionLocation;
        ViewState["listtxtproductionrate"] = listtxtproductionrate;
        ViewState["listtxtproductionamount"] = listtxtproductionamount;
    }
    protected void overrideproductionaddmore(string TableSource)
    {
        listproductioncounter = (List<string>)ViewState["listproductioncounter"];
        listddlproductionitems = (List<string>)ViewState["listddlproductionitems"];
        listhidproductionsjiid = (List<string>)ViewState["listhidproductionsjiid"];
        listhidproductionsidid = (List<string>)ViewState["listhidproductionsidid"];
        listtxtproductionunit = (List<string>)ViewState["listtxtproductionunit"];
        listhidproductionuomid = (List<string>)ViewState["listhidproductionuomid"];
        listtxtproductionquantity = (List<string>)ViewState["listtxtproductionquantity"];
        listbtnproductionqty = (List<string>)ViewState["listbtnproductionqty"];
        listhidproductionLocation = (List<string>)ViewState["listhidproductionLocation"];
        listtxtproductionrate = (List<string>)ViewState["listtxtproductionrate"];
        listtxtproductionamount = (List<string>)ViewState["listtxtproductionamount"];

        if (listproductioncounter != null)
        {
            int tempccounter = Convert.ToInt32(listproductioncounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                productionCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "20%;");
                DropDownList ddlproductionitems = new DropDownList();
                ddlproductionitems.ID = listddlproductionitems[i].ToString();
                ddlproductionitems.CssClass = "dropdown";
                //ddlproductionitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                production_binditem(ddlproductionitems);
                ddlproductionitems.Attributes.Add("onchange", "return checkItemRepetion(this.id,'" + TableSource + "');");
                ddlproductionitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddlproductionitems.SelectedIndexChanged += new EventHandler(production_ddlitems_OnSelectedIndexChanged);

                HiddenField hidproductionsjiid = new HiddenField();
                hidproductionsjiid.ID = listhidproductionsjiid[i].ToString();

                HiddenField hidproductionsidid = new HiddenField();
                hidproductionsidid.ID = listhidproductionsidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "20%;");
                TextBox txtproductionunit = new TextBox();
                txtproductionunit.ID = listtxtproductionunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtproductionunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtproductionunit.CssClass = "DisableInput";


                HiddenField hidproductionuomid = new HiddenField();
                hidproductionuomid.ID = listhidproductionuomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "20%;");
                TextBox txtproductionquantity = new TextBox();
                txtproductionquantity.ID = listtxtproductionquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtproductionquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtproductionquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnproductionqty = new Button();
                btnproductionqty.ID = listbtnproductionqty[i].ToString();
                btnproductionqty.CssClass = "button";
                btnproductionqty.Width = Unit.Percentage(5);
                btnproductionqty.Text = "...";

                HiddenField hidproductionLocation = new HiddenField();
                hidproductionLocation.ID = listhidproductionLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "20%;");
                TextBox txtproductionrate = new TextBox();
                txtproductionrate.ID = listtxtproductionrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtproductionrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtproductionrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('production');");
                txtproductionrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "20%;");
                TextBox txtproductionamount = new TextBox();
                txtproductionamount.ID = listtxtproductionamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtproductionamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtproductionamount.CssClass = "DisableInputNumber";


                cell1.Controls.Add(ddlproductionitems);
                cell1.Controls.Add(hidproductionsjiid);
                cell1.Controls.Add(hidproductionsidid);
                cell2.Controls.Add(txtproductionunit);
                cell2.Controls.Add(hidproductionuomid);
                cell3.Controls.Add(txtproductionquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnproductionqty);
                cell3.Controls.Add(hidproductionLocation);
                cell4.Controls.Add(txtproductionrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtproductionamount);
                //cell5.Controls.Add(hidtaxamt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_production.Rows.Add(row1);
            }
        }
    }
    #endregion ADD MORE production
    protected void btnproductionaddmore_Click(object sender, EventArgs e)
    {
        production_ADDMORE("production");
        production_BindJavaScriptItemQtyPopUp();
    }
    #region ADD MORE physical
    protected void physical_ADDMORE(string TableSource)
    {
        physicalCounter++;
        listphysicalcounter.Add(physicalCounter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();
        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "Center";
        cell1.Style.Add("width", "19%;");
        DropDownList ddlphysicalitems = new DropDownList();
        ddlphysicalitems.ID = "ddl" + TableSource + "items" + physicalCounter.ToString();
        ddlphysicalitems.CssClass = "dropdown";
        //ddlphysicalitems.Width = Unit.Percentage(95);
        //StringBuilder sb = new StringBuilder();
        //sb.Append(TableSource);
        //sb.Append("_binditem");
        // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
        physical_binditem(ddlphysicalitems);
        ddlphysicalitems.Attributes.Add("onchange","return checkItemRepetion(this.id,'" + TableSource + "');");
        ddlphysicalitems.AutoPostBack = true;
        //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
        //ddl.selectedindexchanged += new eventhandler(t);
        ddlphysicalitems.SelectedIndexChanged += new EventHandler(physical_ddlitems_OnSelectedIndexChanged);

        listddlphysicalitems.Add(ddlphysicalitems.ID);

        HiddenField hidphysicalsjiid = new HiddenField();
        hidphysicalsjiid.ID = "hid" + TableSource + "sjiid" + physicalCounter.ToString();
        listhidphysicalsjiid.Add(hidphysicalsjiid.ID);

        HiddenField hidphysicalsidid = new HiddenField();
        hidphysicalsidid.ID = "hid" + TableSource + "sidid" + physicalCounter.ToString();
        listhidphysicalsidid.Add(hidphysicalsidid.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        cell2.Style.Add("width", "19%;");
        TextBox txtphysicalunit = new TextBox();
        txtphysicalunit.ID = "txt" + TableSource + "unit" + physicalCounter.ToString();
        //txtunit.Width = Unit.Percentage(95);
        txtphysicalunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtphysicalunit.CssClass = "DisableInput";

        listtxtphysicalunit.Add(txtphysicalunit.ID);

        HiddenField hidphysicaluomid = new HiddenField();
        hidphysicaluomid.ID = "hid" + TableSource + "uomid" + physicalCounter.ToString();
        listhidphysicaluomid.Add(hidphysicaluomid.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "Center";
        cell3.Style.Add("width", "19%;");
        TextBox txtphysicalquantity = new TextBox();
        txtphysicalquantity.ID = "txt" + TableSource + "quantity" + physicalCounter.ToString();
        //txtquantity.Width = Unit.Percentage(88);
        txtphysicalquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtphysicalquantity.CssClass = "DisableInputNumber";

        listtxtphysicalquantity.Add(txtphysicalquantity.ID);

        Label lblspace = new Label();
        lblspace.Text = "&nbsp;";

        Button btnphysicalqty = new Button();
        btnphysicalqty.ID = "btn" + TableSource + "qty" + physicalCounter.ToString();
        btnphysicalqty.CssClass = "button";
        btnphysicalqty.Width = Unit.Percentage(5);
        btnphysicalqty.Text = "...";

        listbtnphysicalqty.Add(btnphysicalqty.ID);

        HiddenField hidphysicalLocation = new HiddenField();
        hidphysicalLocation.ID = "hid" + TableSource + "Location" + physicalCounter.ToString();

        listhidphysicalLocation.Add(hidphysicalLocation.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        cell4.Style.Add("width", "19%;");
        TextBox txtphysicalrate = new TextBox();
        txtphysicalrate.ID = "txt" + TableSource + "rate" + physicalCounter.ToString();
        //txtrate.Width = Unit.Percentage(95);
        txtphysicalrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtphysicalrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('physical');");
        txtphysicalrate.CssClass = "inputnumber";

        listtxtphysicalrate.Add(txtphysicalrate.ID);

        //HiddenField hidTaxRate = new HiddenField();
        //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
        //listhidTaxRate.Add(hidTaxRate.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        cell5.Style.Add("width", "19%;");
        TextBox txtphysicalamount = new TextBox();
        txtphysicalamount.ID = "txt" + TableSource + "amount" + physicalCounter.ToString();
        //txtamount.Width = Unit.Percentage(95);
        txtphysicalamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
        txtphysicalamount.CssClass = "DisableInputNumber";

        listtxtphysicalamount.Add(txtphysicalamount.ID);

        HtmlTableCell cell6 = new HtmlTableCell();
        cell6.Align = "Center";
        cell6.Style.Add("width", "19%;");
        TextBox txtphysicalreason = new TextBox();
        txtphysicalreason.ID = "txt" + TableSource + "reason" + physicalCounter.ToString();
        txtphysicalreason.CssClass = "input";

        listtxtphysicalreason.Add(txtphysicalreason.ID);

        cell1.Controls.Add(ddlphysicalitems);
        cell1.Controls.Add(hidphysicalsjiid);
        cell1.Controls.Add(hidphysicalsidid);
        cell2.Controls.Add(txtphysicalunit);
        cell2.Controls.Add(hidphysicaluomid);
        cell3.Controls.Add(txtphysicalquantity);
        cell3.Controls.Add(lblspace);
        cell3.Controls.Add(btnphysicalqty);
        cell3.Controls.Add(hidphysicalLocation);
        cell4.Controls.Add(txtphysicalrate);
        //cell4.Controls.Add(hidTaxRate);
        cell5.Controls.Add(txtphysicalamount);
        //cell5.Controls.Add(hidtaxamt);
        cell6.Controls.Add(txtphysicalreason);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);
        row1.Cells.Add(cell6);

        //HtmlTable tt = new HtmlTable();
        //tt.ID = "tbl_" + TableSource.ToString();
        //tt.Rows.Add(row1);
        tbl_physical.Rows.Add(row1);
        hidphysicalCount.Value = physicalCounter.ToString();

        ViewState["listphysicalcounter"] = listphysicalcounter;
        ViewState["listddlphysicalitems"] = listddlphysicalitems;
        ViewState["listhidphysicalsjiid"] = listhidphysicalsjiid;
        ViewState["listhidphysicalsidid"] = listhidphysicalsidid;
        ViewState["listtxtphysicalunit"] = listtxtphysicalunit;
        ViewState["listhidphysicaluomid"] = listhidphysicaluomid;
        ViewState["listtxtphysicalquantity"] = listtxtphysicalquantity;
        ViewState["listbtnphysicalqty"] = listbtnphysicalqty;
        ViewState["listhidphysicalLocation"] = listhidphysicalLocation;
        ViewState["listtxtphysicalrate"] = listtxtphysicalrate;
        ViewState["listtxtphysicalamount"] = listtxtphysicalamount;
        ViewState["listtxtphysicalreason"] = listtxtphysicalreason;
    }
    protected void overridephysicaladdmore(string TableSource)
    {
        listphysicalcounter = (List<string>)ViewState["listphysicalcounter"];
        listddlphysicalitems = (List<string>)ViewState["listddlphysicalitems"];
        listhidphysicalsjiid = (List<string>)ViewState["listhidphysicalsjiid"];
        listhidphysicalsidid = (List<string>)ViewState["listhidphysicalsidid"];
        listtxtphysicalunit = (List<string>)ViewState["listtxtphysicalunit"];
        listhidphysicaluomid = (List<string>)ViewState["listhidphysicaluomid"];
        listtxtphysicalquantity = (List<string>)ViewState["listtxtphysicalquantity"];
        listbtnphysicalqty = (List<string>)ViewState["listbtnphysicalqty"];
        listhidphysicalLocation = (List<string>)ViewState["listhidphysicalLocation"];
        listtxtphysicalrate = (List<string>)ViewState["listtxtphysicalrate"];
        listtxtphysicalamount = (List<string>)ViewState["listtxtphysicalamount"];
        listtxtphysicalreason = (List<string>)ViewState["listtxtphysicalreason"];

        if (listphysicalcounter != null)
        {
            int tempccounter = Convert.ToInt32(listphysicalcounter.Count);
            for (int i = 0; i < tempccounter; i++)
            {

                physicalCounter++;
                HtmlTableRow row1 = new HtmlTableRow();
                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "Center";
                cell1.Style.Add("width", "19%;");
                DropDownList ddlphysicalitems = new DropDownList();
                ddlphysicalitems.ID = listddlphysicalitems[i].ToString();
                ddlphysicalitems.CssClass = "dropdown";
                //ddlphysicalitems.Width = Unit.Percentage(95);
                //StringBuilder sb = new StringBuilder();
                //sb.Append(TableSource);
                //sb.Append("_binditem");
                // lblMsg.Text = sb.ToString() + "(" + "ddl" + TableSource + "items" + Counter.ToString() + ")";
                physical_binditem(ddlphysicalitems);
                ddlphysicalitems.Attributes.Add("onchange","return checkItemRepetion(this.id,'" + TableSource + "');");
                ddlphysicalitems.AutoPostBack = true;
                //public event  t=tablesource+"_ddlitems_onselectedindexchanged";
                //ddl.selectedindexchanged += new eventhandler(t);
                ddlphysicalitems.SelectedIndexChanged += new EventHandler(physical_ddlitems_OnSelectedIndexChanged);

                HiddenField hidphysicalsjiid = new HiddenField();
                hidphysicalsjiid.ID = listhidphysicalsjiid[i].ToString();

                HiddenField hidphysicalsidid = new HiddenField();
                hidphysicalsidid.ID = listhidphysicalsidid[i].ToString();

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                cell2.Style.Add("width", "19%;");
                TextBox txtphysicalunit = new TextBox();
                txtphysicalunit.ID = listtxtphysicalunit[i].ToString();
                //txtunit.Width = Unit.Percentage(95);
                txtphysicalunit.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtphysicalunit.CssClass = "DisableInput";


                HiddenField hidphysicaluomid = new HiddenField();
                hidphysicaluomid.ID = listhidphysicaluomid[i].ToString();

                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "Center";
                cell3.Style.Add("width", "19%;");
                TextBox txtphysicalquantity = new TextBox();
                txtphysicalquantity.ID = listtxtphysicalquantity[i].ToString();
                //txtquantity.Width = Unit.Percentage(88);
                txtphysicalquantity.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtphysicalquantity.CssClass = "DisableInputNumber";

                Label lblspace = new Label();
                lblspace.Text = "&nbsp;";

                Button btnphysicalqty = new Button();
                btnphysicalqty.ID = listbtnphysicalqty[i].ToString();
                btnphysicalqty.CssClass = "button";
                btnphysicalqty.Width = Unit.Percentage(5);
                btnphysicalqty.Text = "...";

                HiddenField hidphysicalLocation = new HiddenField();
                hidphysicalLocation.ID = listhidphysicalLocation[i].ToString();

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                cell4.Style.Add("width", "19%;");
                TextBox txtphysicalrate = new TextBox();
                txtphysicalrate.ID = listtxtphysicalrate[i].ToString();
                //txtrate.Width = Unit.Percentage(95);
                txtphysicalrate.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtphysicalrate.Attributes.Add("onBlur", "return CalculateAmtBillLevel('physical');");
                txtphysicalrate.CssClass = "inputnumber";

                //HiddenField hidTaxRate = new HiddenField();
                //hidTaxRate.ID = "hidTaxRate" + dccounter.ToString();
                //listhidTaxRate.Add(hidTaxRate.ID);

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                cell5.Style.Add("width", "19%;");
                TextBox txtphysicalamount = new TextBox();
                txtphysicalamount.ID = listtxtphysicalamount[i].ToString();
                //txtamount.Width = Unit.Percentage(95);
                txtphysicalamount.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                txtphysicalamount.CssClass = "DisableInputNumber";

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "Center";
                cell6.Style.Add("width", "19%;");
                TextBox txtphysicalreason = new TextBox();
                txtphysicalreason.ID = listtxtphysicalreason[i].ToString();
                txtphysicalreason.CssClass = "input";

                cell1.Controls.Add(ddlphysicalitems);
                cell1.Controls.Add(hidphysicalsjiid);
                cell1.Controls.Add(hidphysicalsidid);
                cell2.Controls.Add(txtphysicalunit);
                cell2.Controls.Add(hidphysicaluomid);
                cell3.Controls.Add(txtphysicalquantity);
                cell3.Controls.Add(lblspace);
                cell3.Controls.Add(btnphysicalqty);
                cell3.Controls.Add(hidphysicalLocation);
                cell4.Controls.Add(txtphysicalrate);
                //cell4.Controls.Add(hidTaxRate);
                cell5.Controls.Add(txtphysicalamount);
                //cell5.Controls.Add(hidtaxamt);
                cell6.Controls.Add(txtphysicalreason);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);

                //HtmlTable tt = new HtmlTable();
                //tt.ID = "tbl_" + TableSource.ToString();
                //tt.Rows.Add(row1);
                tbl_physical.Rows.Add(row1);
            }
        }
    }
    #endregion ADD MORE physical
    protected void btnphyaddmore_Click(object sender, EventArgs e)
    {
        physical_ADDMORE("physical");
        physical_BindJavaScriptItemQtyPopUp();
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        
        if (ddljrnFormate.SelectedValue != "0")
        {
            string TFOID = ddljrnFormate.SelectedValue.ToString();
            string SJRNUM = txtjrnno.Text.ToString();
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            string TYPEOFENTRY = "7";
            string ISSUE_RECEIPT = "0";

            if (hid_TFOID.Value == "1") // Stock Journal ( INPUT and OUTPUT )
            {
                SqlParameter[] paraIssue = {
                                            new SqlParameter("@SJRID",Convert.ToInt32(Request.QueryString["SJRID"].ToString())), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@Ename",USERNAME)
                                           };
                int result = DU.executeprocedure("usp_ivr_UpdateJournal", paraIssue);
                if (result > 0)
                {
                   //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                   //DataTable dtSTKJRNL = DU.getdata(strsql);
                   // if (dtSTKJRNL.Rows.Count > 0)
                    //{
                    Save_input_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_input_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());

                    Save_output_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                        //Save_output_ivr_stkjrnl_others(dtSTKJRNL.Rows[0]["SJRID"].ToString());

                        //ClearForm();
                        //BindJournalNo(TFOID);
                        //ResetTableControl(tbl_input);
                        //ResetTableControl(tbl_output);
                        //ResetTableControl(tbl_details);
                        //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                    //}
                }
            }
            if (hid_TFOID.Value == "2") // Production Journal
            {
                SqlParameter[] paraProduction = {
                                            new SqlParameter("@SJRID",Request.QueryString["SJRID"].ToString()), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@Ename",USERNAME)
                                           };
                int result = DU.executeprocedure("USP_IVR_UpdateJournal", paraProduction);
                if (result > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                    //DataTable dtSTKJRNL = DU.getdata(strsql);
                    //if (dtSTKJRNL.Rows.Count > 0)
                    //{
                    Save_production_First_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_production_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_production_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());
                        //ClearForm();
                        //BindJournalNo(TFOID);
                        //ResetTableControl(tbl_production);
                        //ResetTableControl(tbl_details);
                        //ClearPRODTable();  // Prod First Table Clear
                        //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                    //}
                }
            }
            if (hid_TFOID.Value == "3") // Stock Issue
            {
                    SqlParameter[] paraIssue = {
                                            new SqlParameter("@SJRID",Request.QueryString["SJRID"].ToString()), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@Ename",USERNAME)
                                             };
                    int result = DU.executeprocedure("USP_IVR_UpdateJournal", paraIssue);
                    if (result > 0)
                    {
                        //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                        //DataTable dtSTKJRNL = DU.getdata(strsql);
                        //if (dtSTKJRNL.Rows.Count > 0)
                        //{
                        Save_Issue_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                        Save_Issue_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());
                            //ClearForm();
                            //BindJournalNo(TFOID);
                            //ResetTableControl(tbl_issue);
                            //ResetTableControl(tbl_details);
                            //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                        //}
                    }
            }
            if (hid_TFOID.Value == "4") // Stock Receipt
            {
                SqlParameter[] paraIssue = {
                                            new SqlParameter("@SJRID",Request.QueryString["SJRID"].ToString()), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@Ename",USERNAME)
                                           };
                int result = DU.executeprocedure("USP_IVR_UpdateJournal", paraIssue);
                if (result > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                    //DataTable dtSTKJRNL = DU.getdata(strsql);
                    //if (dtSTKJRNL.Rows.Count > 0)
                    //{
                    Save_recieved_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_recieved_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());
                        //ClearForm();
                        //BindJournalNo(TFOID);
                        //ResetTableControl(tbl_recieved);
                        //ResetTableControl(tbl_details);
                        //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                    //}
                }
            }
            if (hid_TFOID.Value == "5")  // Stock Transfer
            {
                SqlParameter[] paraIssue = {
                                            new SqlParameter("@SJRID",Request.QueryString["SJRID"].ToString()), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@FROM_WHSID",ddlfromLoacation.SelectedValue),
                                            new SqlParameter("@TO_WHSID",ddlToLoacation.SelectedValue),
                                            new SqlParameter("@Ename",USERNAME)
                                           };
                int result = DU.executeprocedure("USP_IVR_UpdateJournal", paraIssue);
                if (result > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                    //DataTable dtSTKJRNL = DU.getdata(strsql);
                    //if (dtSTKJRNL.Rows.Count > 0)
                    //{
                    Save_transfer_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_transfer_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());
                        //ClearForm();
                        //BindJournalNo(TFOID);
                        //ResetTableControl(tbl_transfer);
                        //ResetTableControl(tbl_details);
                        //ResetTableControl(tdfromto);
                        //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                    //}
                }
            }
            if (hid_TFOID.Value == "6") // Physical Stock
            {
                SqlParameter[] paraIssue = {
                                            new SqlParameter("@SJRID",Request.QueryString["SJRID"].ToString()), // 0 for Insert
                                            new SqlParameter("@FINYEAR",FINYEAR),
                                            new SqlParameter("@TFOID",TFOID),
                                            new SqlParameter("@SJRNUM",SJRNUM),
                                            new SqlParameter("@SJRDATE",strDate),
                                            new SqlParameter("@Ename",USERNAME)
                                           };
                int result = DU.executeprocedure("USP_IVR_UpdateJournal", paraIssue);
                if (result > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL')as SJRID ";
                    //DataTable dtSTKJRNL = DU.getdata(strsql);
                    //if (dtSTKJRNL.Rows.Count > 0)
                    //{
                    Save_physical_ivr_stkjrnl_item(Request.QueryString["SJRID"].ToString());
                    Save_physical_ivr_stkjrnl_others(Request.QueryString["SJRID"].ToString());
                        //ClearForm();
                        //BindJournalNo(TFOID);
                        //ResetTableControl(tbl_recieved);
                        //ResetTableControl(tbl_details);
                        //txtdate.Text = string.Empty;
                        lblMsg.Text = "Updated Successfully....";
                    //}
                }
            }

        }
    }   // Save All Category

    protected void Save_Issue_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int issueTempCount = Convert.ToInt32(hidissueCount.Value.ToString());
            for (int i = 1; i <= issueTempCount; i++)
            {
                DropDownList ddlissueitems = (DropDownList)tbl_issue.Rows[i].FindControl("ddlissueitems" + i.ToString());
                HiddenField hidissueuomid = (HiddenField)tbl_issue.Rows[i].FindControl("hidissueuomid" + i.ToString());
                TextBox txtissuequantity = (TextBox)tbl_issue.Rows[i].FindControl("txtissuequantity" + i.ToString());
                TextBox txtissuerate = (TextBox)tbl_issue.Rows[i].FindControl("txtissuerate" + i.ToString());
                TextBox txtissueamount = (TextBox)tbl_issue.Rows[i].FindControl("txtissueamount" + i.ToString());
                HiddenField hidissuesjiid = (HiddenField)tbl_issue.Rows[i].FindControl("hidissuesjiid" + i.ToString());

                if (txtissuequantity.Text != string.Empty && txtissuerate.Text != string.Empty)
                {
                    if (hidissuesjiid.Value != string.Empty)
                    {
                        SqlParameter[] paraIssueItem = {
                                        new SqlParameter("@SJIID",hidissuesjiid.Value.ToString()),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtissuequantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidissueuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtissuerate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtissueamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraIssueItem);
                    }
                    else
                    {
                        SqlParameter[] paraIssueItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtissuequantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidissueuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtissuerate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtissueamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraIssueItem);
                    }
                }
                if (ddlissueitems.SelectedValue == "0" && txtissuequantity.Text.ToString() == string.Empty && txtissuerate.Text == string.Empty && hidissuesjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidissuesjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    if (hidissuesjiid.Value != string.Empty)
                    {
                        Save_Issue_ivr_stkjrnl_itemdet(hidissuesjiid.Value, SJRID, i);
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_Issue_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_Issue_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlissueitems = (DropDownList)tbl_issue.Rows[RowNo].FindControl("ddlissueitems" + RowNo.ToString());
            TextBox txtissuequantity = (TextBox)tbl_issue.Rows[RowNo].FindControl("txtissuequantity" + RowNo.ToString());
            TextBox txtissuerate = (TextBox)tbl_issue.Rows[RowNo].FindControl("txtissuerate" + RowNo.ToString());
            HiddenField hidissueLocation = (HiddenField)tbl_issue.Rows[RowNo].FindControl("hidissueLocation" + RowNo.ToString());
            HiddenField hidissuesjiid = (HiddenField)tbl_issue.Rows[RowNo].FindControl("hidissuesjiid" + RowNo.ToString());
            HiddenField hidissuesidid = (HiddenField)tbl_issue.Rows[RowNo].FindControl("hidissuesidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidissuesidid.Value.ToString() != string.Empty)
            {
                if (hidissuesidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidissuesidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidissuesidid.Value);
                }
            }

            if (txtissuequantity.Text != string.Empty && txtissuerate.Text != string.Empty)
            {
                if (hidissueLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlissueitems.SelectedValue) && isWarrantyEnabled(ddlissueitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidissueLocation.Value.ToString().Contains("/") && hidissueLocation.Value.ToString().Contains("|") && hidissueLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidissueLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidissueLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                       // DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlissueitems.SelectedValue) && !isWarrantyEnabled(ddlissueitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidissueLocation.Value.ToString().Contains("/") && hidissueLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidissueLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidissueLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlissueitems.SelectedValue) && !isWarrantyEnabled(ddlissueitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidissueLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidissueLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidissueLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlissueitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtissuerate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }
    protected void Save_Issue_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if(result3>0)
        {
            
        }
    }

    protected void Save_recieved_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int recievedTempCount = Convert.ToInt32(hidrecievedCount.Value.ToString());
            for (int i = 1; i <= recievedTempCount; i++)
            {
                DropDownList ddlrecieveditems = (DropDownList)tbl_recieved.Rows[i].FindControl("ddlrecieveditems" + i.ToString());
                HiddenField hidrecieveduomid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecieveduomid" + i.ToString());
                TextBox txtrecievedquantity = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedquantity" + i.ToString());
                TextBox txtrecievedrate = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedrate" + i.ToString());
                TextBox txtrecievedamount = (TextBox)tbl_recieved.Rows[i].FindControl("txtrecievedamount" + i.ToString());
                HiddenField hidrecievedsjiid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedsjiid" + i.ToString());
                HiddenField hidrecievedsidid = (HiddenField)tbl_recieved.Rows[i].FindControl("hidrecievedsidid" + i.ToString());

                if (txtrecievedquantity.Text != string.Empty && txtrecievedrate.Text != string.Empty)
                {
                    if (hidrecievedsjiid.Value != string.Empty)
                    {
                        SqlParameter[] pararecievedItem = {
                                        new SqlParameter("@SJIID",hidrecievedsjiid.Value),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtrecievedquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidrecieveduomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtrecievedrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtrecievedamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", pararecievedItem);
                    }
                    else
                    {
                        SqlParameter[] pararecievedItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtrecievedquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidrecieveduomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtrecievedrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtrecievedamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", pararecievedItem);
                    }
                }
                if (ddlrecieveditems.SelectedValue == "0" && txtrecievedquantity.Text.ToString() == string.Empty && txtrecievedrate.Text == string.Empty && hidrecievedsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidrecievedsjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    if (hidrecievedsjiid.Value != string.Empty)
                    {
                        //strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        //DataTable dtItemDetails = DU.getdata(strsql);
                        //if (dtItemDetails.Rows.Count > 0)
                        //{
                        Save_recieved_ivr_stkjrnl_itemdet(hidrecievedsjiid.Value, SJRID, i);
                        //}
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_recieved_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_recieved_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlrecieveditems = (DropDownList)tbl_recieved.Rows[RowNo].FindControl("ddlrecieveditems" + RowNo.ToString());
            TextBox txtrecievedquantity = (TextBox)tbl_recieved.Rows[RowNo].FindControl("txtrecievedquantity" + RowNo.ToString());
            TextBox txtrecievedrate = (TextBox)tbl_recieved.Rows[RowNo].FindControl("txtrecievedrate" + RowNo.ToString());
            HiddenField hidrecievedLocation = (HiddenField)tbl_recieved.Rows[RowNo].FindControl("hidrecievedLocation" + RowNo.ToString());
            HiddenField hidrecievedsjiid = (HiddenField)tbl_recieved.Rows[RowNo].FindControl("hidrecievedsjiid" + RowNo.ToString());
            HiddenField hidrecievedsidid = (HiddenField)tbl_recieved.Rows[RowNo].FindControl("hidrecievedsidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidrecievedsidid.Value.ToString() != string.Empty)
            {
                if (hidrecievedsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidrecievedsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidrecievedsidid.Value);
                }
            }

            if (txtrecievedquantity.Text != string.Empty && txtrecievedrate.Text != string.Empty)
            {
                if (hidrecievedLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlrecieveditems.SelectedValue) && isWarrantyEnabled(ddlrecieveditems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidrecievedLocation.Value.ToString().Contains("/") && hidrecievedLocation.Value.ToString().Contains("|") && hidrecievedLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidrecievedLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidrecievedLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlrecieveditems.SelectedValue) && !isWarrantyEnabled(ddlrecieveditems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidrecievedLocation.Value.ToString().Contains("/") && hidrecievedLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidrecievedLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidrecievedLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlrecieveditems.SelectedValue) && !isWarrantyEnabled(ddlrecieveditems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidrecievedLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidrecievedLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidrecievedLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                    };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlrecieveditems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",lstLocationQty[j].ToString()),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtrecievedrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }
    protected void Save_recieved_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)
        {

        }
    }

    protected void Save_physical_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int physicalTempCount = Convert.ToInt32(hidphysicalCount.Value.ToString());
            for (int i = 1; i <= physicalTempCount; i++)
            {
                DropDownList ddlphysicalitems = (DropDownList)tbl_physical.Rows[i].FindControl("ddlphysicalitems" + i.ToString());
                HiddenField hidphysicaluomid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicaluomid" + i.ToString());
                TextBox txtphysicalquantity = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalquantity" + i.ToString());
                TextBox txtphysicalrate = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalrate" + i.ToString());
                TextBox txtphysicalamount = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalamount" + i.ToString());
                TextBox txtphysicalreason = (TextBox)tbl_physical.Rows[i].FindControl("txtphysicalreason" + i.ToString());
                HiddenField hidphysicalsjiid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalsjiid" + i.ToString());
                HiddenField hidphysicalsidid = (HiddenField)tbl_physical.Rows[i].FindControl("hidphysicalsidid" + i.ToString());

                if (txtphysicalquantity.Text != string.Empty && txtphysicalrate.Text != string.Empty)
                {
                    if (hidphysicalsjiid.Value != string.Empty)
                    {
                        SqlParameter[] paraphysicalItem = {
                                        new SqlParameter("@SJIID",hidphysicalsjiid.Value.ToString()),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtphysicalquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidphysicaluomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtphysicalrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtphysicalamount.Text.Trim().ToString()),
                                        new SqlParameter("@REASON",txtphysicalreason.Text.ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_UpdateJournalItems", paraphysicalItem);
                    }
                    else
                    {
                        SqlParameter[] paraphysicalItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtphysicalquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidphysicaluomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtphysicalrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtphysicalamount.Text.Trim().ToString()),
                                        new SqlParameter("@REASON",txtphysicalreason.Text.ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraphysicalItem);
                    }
                }
                if (ddlphysicalitems.SelectedValue == "0" && txtphysicalquantity.Text.ToString() == string.Empty && txtphysicalrate.Text == string.Empty && hidphysicalsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidphysicalsjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    if (hidphysicalsjiid.Value != string.Empty)
                    {
                        //strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        //DataTable dtItemDetails = DU.getdata(strsql);
                        //if (dtItemDetails.Rows.Count > 0)
                        //{
                        Save_physical_ivr_stkjrnl_itemdet(hidphysicalsjiid.Value, SJRID, i);
                        //}
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_physical_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_physical_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlphysicalitems = (DropDownList)tbl_physical.Rows[RowNo].FindControl("ddlphysicalitems" + RowNo.ToString());
            TextBox txtphysicalquantity = (TextBox)tbl_physical.Rows[RowNo].FindControl("txtphysicalquantity" + RowNo.ToString());
            TextBox txtphysicalrate = (TextBox)tbl_physical.Rows[RowNo].FindControl("txtphysicalrate" + RowNo.ToString());
            HiddenField hidphysicalLocation = (HiddenField)tbl_physical.Rows[RowNo].FindControl("hidphysicalLocation" + RowNo.ToString());
            HiddenField hidphysicalsjiid = (HiddenField)tbl_physical.Rows[RowNo].FindControl("hidphysicalsjiid" + RowNo.ToString());
            HiddenField hidphysicalsidid = (HiddenField)tbl_physical.Rows[RowNo].FindControl("hidphysicalsidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidphysicalsidid.Value.ToString() != string.Empty)
            {
                if (hidphysicalsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidphysicalsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidphysicalsidid.Value);
                }
            }
            if (txtphysicalquantity.Text != string.Empty && txtphysicalrate.Text != string.Empty)
            {
                if (hidphysicalLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlphysicalitems.SelectedValue) && isWarrantyEnabled(ddlphysicalitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidphysicalLocation.Value.ToString().Contains("/") && hidphysicalLocation.Value.ToString().Contains("|") && hidphysicalLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidphysicalLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidphysicalLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlphysicalitems.SelectedValue) && !isWarrantyEnabled(ddlphysicalitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidphysicalLocation.Value.ToString().Contains("/") && hidphysicalLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidphysicalLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidphysicalLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j < lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlphysicalitems.SelectedValue) && !isWarrantyEnabled(ddlphysicalitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidphysicalLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidphysicalLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidphysicalLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlphysicalitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT","0"),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }
    protected void Save_physical_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)
        {

        }
    }

    protected void Save_input_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int inputTempCount = Convert.ToInt32(hidinputCount.Value.ToString());
            for (int i = 1; i <= inputTempCount; i++)
            {
                DropDownList ddlinputitems = (DropDownList)tbl_input.Rows[i].FindControl("ddlinputitems" + i.ToString());
                HiddenField hidinputuomid = (HiddenField)tbl_input.Rows[i].FindControl("hidinputuomid" + i.ToString());
                TextBox txtinputquantity = (TextBox)tbl_input.Rows[i].FindControl("txtinputquantity" + i.ToString());
                TextBox txtinputrate = (TextBox)tbl_input.Rows[i].FindControl("txtinputrate" + i.ToString());
                TextBox txtinputamount = (TextBox)tbl_input.Rows[i].FindControl("txtinputamount" + i.ToString());
                HiddenField hidinputsjiid = (HiddenField)tbl_input.Rows[i].FindControl("hidinputsjiid" + i.ToString());

                if (txtinputquantity.Text != string.Empty && txtinputrate.Text != string.Empty)
                {
                    if (hidinputsjiid.Value != string.Empty)
                    {
                        SqlParameter[] parainputItem = {
                                        new SqlParameter("@SJIID",hidinputsjiid.Value),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtinputquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidinputuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtinputrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtinputamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("usp_ivr_UpdateJournalItems", parainputItem);
                    }
                    else
                    {
                        SqlParameter[] parainputItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtinputquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidinputuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtinputrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtinputamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", parainputItem);
                    }
                }
                if (ddlinputitems.SelectedValue == "0" && txtinputquantity.Text.ToString() == string.Empty && txtinputrate.Text == string.Empty && hidinputsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidinputsjiid.Value + "and SJRID=" +SJRID + "");
                }
                if (result1 > 0)
                {
                    if (hidinputsjiid.Value != string.Empty)
                    {
                        Save_input_ivr_stkjrnl_itemdet(hidinputsjiid.Value, SJRID, i);
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_input_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_input_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlinputitems = (DropDownList)tbl_input.Rows[RowNo].FindControl("ddlinputitems" + RowNo.ToString());
            TextBox txtinputquantity = (TextBox)tbl_input.Rows[RowNo].FindControl("txtinputquantity" + RowNo.ToString());
            TextBox txtinputrate = (TextBox)tbl_input.Rows[RowNo].FindControl("txtinputrate" + RowNo.ToString());
            HiddenField hidinputLocation = (HiddenField)tbl_input.Rows[RowNo].FindControl("hidinputLocation" + RowNo.ToString());
            HiddenField hidinputsidid = (HiddenField)tbl_input.Rows[RowNo].FindControl("hidinputsidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidinputsidid.Value.ToString() != string.Empty)
            {
                if (hidinputsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidinputsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidinputsidid.Value);
                }
            }

            if (txtinputquantity.Text != string.Empty && txtinputrate.Text != string.Empty)
            {
                if (hidinputLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlinputitems.SelectedValue) && isWarrantyEnabled(ddlinputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidinputLocation.Value.ToString().Contains("/") && hidinputLocation.Value.ToString().Contains("|") && hidinputLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidinputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidinputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                       // }
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlinputitems.SelectedValue) && !isWarrantyEnabled(ddlinputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidinputLocation.Value.ToString().Contains("/") && hidinputLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidinputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidinputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlinputitems.SelectedValue) && !isWarrantyEnabled(ddlinputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidinputLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidinputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidinputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                       // strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                       // DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddlinputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtinputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID="+SJIID+"");
            //        }
            //    }
            //}
        }
    }
    protected void Save_input_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)                 
        {

        }
    }

    protected void Save_output_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }

            int result1 = 0;
            int outputTempCount = Convert.ToInt32(hidoutputCount.Value.ToString());
            for (int i = 1; i <= outputTempCount; i++)
            {
                DropDownList ddloutputitems = (DropDownList)tbl_output.Rows[i].FindControl("ddloutputitems" + i.ToString());
                HiddenField hidoutputuomid = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputuomid" + i.ToString());
                TextBox txtoutputquantity = (TextBox)tbl_output.Rows[i].FindControl("txtoutputquantity" + i.ToString());
                TextBox txtoutputrate = (TextBox)tbl_output.Rows[i].FindControl("txtoutputrate" + i.ToString());
                TextBox txtoutputamount = (TextBox)tbl_output.Rows[i].FindControl("txtoutputamount" + i.ToString());
                HiddenField hidoutputsjiid = (HiddenField)tbl_output.Rows[i].FindControl("hidoutputsjiid" + i.ToString());

                if (txtoutputquantity.Text != string.Empty && txtoutputrate.Text != string.Empty)
                {
                    if (hidoutputsjiid.Value != string.Empty)
                    {
                        SqlParameter[] paraoutputItem = {
                                        new SqlParameter("@SJIID",hidoutputsjiid.Value),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtoutputquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidoutputuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtoutputrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtoutputamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_UpdateJournalItems", paraoutputItem);
                    }
                    else
                    {
                        SqlParameter[] paraoutputItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtoutputquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidoutputuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtoutputrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtoutputamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraoutputItem);
                    }
                }
                if (ddloutputitems.SelectedValue == "0" && txtoutputquantity.Text.ToString() == string.Empty && txtoutputrate.Text == string.Empty && hidoutputsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidoutputsjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    if (hidoutputsjiid.Value != string.Empty)
                    {
                        Save_output_ivr_stkjrnl_itemdet(hidoutputsjiid.Value, SJRID, i);
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_output_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_output_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddloutputitems = (DropDownList)tbl_output.Rows[RowNo].FindControl("ddloutputitems" + RowNo.ToString());
            TextBox txtoutputquantity = (TextBox)tbl_output.Rows[RowNo].FindControl("txtoutputquantity" + RowNo.ToString());
            TextBox txtoutputrate = (TextBox)tbl_output.Rows[RowNo].FindControl("txtoutputrate" + RowNo.ToString());
            HiddenField hidoutputLocation = (HiddenField)tbl_output.Rows[RowNo].FindControl("hidoutputLocation" + RowNo.ToString());
            HiddenField hidoutputsidid = (HiddenField)tbl_output.Rows[RowNo].FindControl("hidoutputsidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidoutputsidid.Value.ToString() != string.Empty)
            {
                if (hidoutputsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidoutputsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidoutputsidid.Value);
                }
            }

            if (txtoutputquantity.Text != string.Empty && txtoutputrate.Text != string.Empty)
            {
                if (hidoutputLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddloutputitems.SelectedValue) && isWarrantyEnabled(ddloutputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidoutputLocation.Value.ToString().Contains("/") && hidoutputLocation.Value.ToString().Contains("|") && hidoutputLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidoutputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidoutputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                        SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                        int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                        if (Result > 0)
                                        {
                                            intResult = 0;
                                        }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddloutputitems.SelectedValue) && !isWarrantyEnabled(ddloutputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidoutputLocation.Value.ToString().Contains("/") && hidoutputLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidoutputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidoutputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddloutputitems.SelectedValue) && !isWarrantyEnabled(ddloutputitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidoutputLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidoutputLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidoutputLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddloutputitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtoutputrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                   int delresult= DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }
    protected void Save_output_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)
        {

        }
    }

    protected void Save_transfer_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int transferTempCount = Convert.ToInt32(hidtransferCount.Value.ToString());
            for (int i = 1; i <= transferTempCount; i++)
            {
                DropDownList ddltransferitems = (DropDownList)tbl_transfer.Rows[i].FindControl("ddltransferitems" + i.ToString());
                HiddenField hidtransferuomid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransferuomid" + i.ToString());
                TextBox txttransferquantity = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferquantity" + i.ToString());
                TextBox txttransferrate = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferrate" + i.ToString());
                TextBox txttransferamount = (TextBox)tbl_transfer.Rows[i].FindControl("txttransferamount" + i.ToString());
                HiddenField hidtransfersjiid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransfersjiid" + i.ToString());
                HiddenField hidtransfersidid = (HiddenField)tbl_transfer.Rows[i].FindControl("hidtransfersidid" + i.ToString());
                

                if (txttransferquantity.Text != string.Empty && txttransferrate.Text != string.Empty)
                {
                    if (hidtransfersjiid.Value != string.Empty)
                    {
                        SqlParameter[] paratransferItem = {
                                        new SqlParameter("@SJIID",hidtransfersjiid.Value),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txttransferquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidtransferuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txttransferrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txttransferamount.Text.Trim().ToString())
                                       
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paratransferItem);
                    }
                    else
                    {
                        SqlParameter[] paratransferItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txttransferquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidtransferuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txttransferrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txttransferamount.Text.Trim().ToString())
                                       
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paratransferItem);
                    }
                }
                if (result1 > 0)
                {
                    if (hidtransfersjiid.Value != string.Empty)
                    {
                        Save_transfer_ivr_stkjrnl_itemdet(hidtransfersjiid.Value.ToString(), SJRID, i);
                    }
                    else
                    {
                        strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                        DataTable dtItemDetails = DU.getdata(strsql);
                        if (dtItemDetails.Rows.Count > 0)
                        {
                            Save_transfer_ivr_stkjrnl_itemdet(dtItemDetails.Rows[0]["SJIID"].ToString(), SJRID, i);
                        }
                    }
                }
            }
        }
    }
    protected void Save_transfer_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddltransferitems = (DropDownList)tbl_transfer.Rows[RowNo].FindControl("ddltransferitems" + RowNo.ToString());
            TextBox txttransferquantity = (TextBox)tbl_transfer.Rows[RowNo].FindControl("txttransferquantity" + RowNo.ToString());
            TextBox txttransferrate = (TextBox)tbl_transfer.Rows[RowNo].FindControl("txttransferrate" + RowNo.ToString());
            HiddenField hidtransferLocation = (HiddenField)tbl_transfer.Rows[RowNo].FindControl("hidtransferLocation" + RowNo.ToString());
            HiddenField hidtransfersjiid = (HiddenField)tbl_transfer.Rows[RowNo].FindControl("hidtransfersjiid" + RowNo.ToString());
            HiddenField hidtransfersidid = (HiddenField)tbl_transfer.Rows[RowNo].FindControl("hidtransfersidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidtransfersidid.Value.ToString() != string.Empty)
            {
                if (hidtransfersidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidtransfersidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidtransfersidid.Value);
                }
            }

            if (txttransferquantity.Text != string.Empty && txttransferrate.Text != string.Empty)
            {
                if (hidtransferLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddltransferitems.SelectedValue) && isWarrantyEnabled(ddltransferitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidtransferLocation.Value.ToString().Contains("/") && hidtransferLocation.Value.ToString().Contains("|") && hidtransferLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidtransferLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidtransferLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_updateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                            SqlParameter[] sparam2 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToDouble(lstSIDIDLocationId[j].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result3 = DU.executeprocedure("USP_IVR_updateStockDetails", sparam2);
                                            if (Result3 > 0)
                                            {
                                                Result3 = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",DTTranTidid.Rows[0]["SJIID"].ToString()),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                            SqlParameter[] sparam2 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToDouble(DTTranTidid.Rows[0]["SJIID"].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result3 = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam2);
                                            if (Result3 > 0)
                                            {
                                                Result3 = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddltransferitems.SelectedValue) && !isWarrantyEnabled(ddltransferitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidtransferLocation.Value.ToString().Contains("/") && hidtransferLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidtransferLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidtransferLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam1 ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult4 = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam1);
                                    if (intResult4 > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                        SqlParameter[] sparam3 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                        int Result5 = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam3);
                                        if (Result5 > 0)
                                        {
                                            Result5 = 0;
                                        }
                                        SqlParameter[] sparam4 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToInt32(lstSIDIDLocationId[j].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                        int Result6 = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam4);
                                        if (Result6 > 0)
                                        {
                                            Result6 = 0;
                                        }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam1 ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult4 = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam1);
                                    if (intResult4 > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam3 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result5 = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam3);
                                            if (Result5 > 0)
                                            {
                                                Result5 = 0;
                                            }
                                            SqlParameter[] sparam4 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToDouble(DTTranTidid.Rows[0]["SJIID"].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result6 = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam4);
                                            if (Result6 > 0)
                                            {
                                                Result6 = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddltransferitems.SelectedValue) && !isWarrantyEnabled(ddltransferitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidtransferLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidtransferLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidtransferLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam4 ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult7 = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam4);
                                    if (intResult7 > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam5 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result8 = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam5);
                                            if (Result8 > 0)
                                            {
                                                Result8 = 0;
                                            }
                                            SqlParameter[] sparam6 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToInt32(lstSIDIDLocationId[j].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result9 = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam6);
                                            if (Result9 > 0)
                                            {
                                                Result9 = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam4 ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult7 = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam4);
                                    if (intResult7 > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam5 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result8 = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam5);
                                            if (Result8 > 0)
                                            {
                                                Result8 = 0;
                                            }
                                            SqlParameter[] sparam6 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",0-Convert.ToDouble(DTTranTidid.Rows[0]["SJIID"].ToString())),
                                                               new SqlParameter("@ITMID",ddltransferitems.SelectedValue),
                                                               new SqlParameter("@WHID",ddlToLoacation.SelectedValue),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txttransferrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result9 = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam6);
                                            if (Result9 > 0)
                                            {
                                                Result9 = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }
    protected void Save_transfer_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)
        {

        }
    }

    protected void Save_production_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            int productionTempCount = Convert.ToInt32(hidproductionCount.Value.ToString());
            for (int i = 1; i <= productionTempCount; i++)
            {
                DropDownList ddlproductionitems = (DropDownList)tbl_production.Rows[i].FindControl("ddlproductionitems" + i.ToString());
                HiddenField hidproductionuomid = (HiddenField)tbl_production.Rows[i].FindControl("hidproductionuomid" + i.ToString());
                TextBox txtproductionquantity = (TextBox)tbl_production.Rows[i].FindControl("txtproductionquantity" + i.ToString());
                TextBox txtproductionrate = (TextBox)tbl_production.Rows[i].FindControl("txtproductionrate" + i.ToString());
                TextBox txtproductionamount = (TextBox)tbl_production.Rows[i].FindControl("txtproductionamount" + i.ToString());
                HiddenField hidproductionsjiid=(HiddenField)tbl_production.Rows[i].FindControl("hidproductionsjiid"+i.ToString());

               
                if (txtproductionquantity.Text != string.Empty && txtproductionrate.Text != string.Empty)
                {
                    if (hidproductionsjiid.Value != string.Empty)
                    {
                        SqlParameter[] paraproductionItem = {
                                        new SqlParameter("@SJIID",hidproductionsjiid.Value),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtproductionquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidproductionuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtproductionrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtproductionamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("usp_ivr_UpdateJournalItems", paraproductionItem);
                    }
                    else
                    {
                        SqlParameter[] paraproductionItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","0"),
                                        new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtproductionquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidproductionuomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtproductionrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtproductionamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraproductionItem);
                    }
                }
                if (ddlproductionitems.SelectedValue == "0" && txtproductionquantity.Text.ToString() == string.Empty && txtproductionrate.Text == string.Empty && hidproductionsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidproductionsjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                    //DataTable dtItemDetails = DU.getdata(strsql);
                    //if (dtItemDetails.Rows.Count > 0)
                    //{
                        Save_production_ivr_stkjrnl_itemdet(hidproductionsjiid.Value, SJRID, i);
                    //}
                }
            }
        }
    }
    protected void Save_production_ivr_stkjrnl_itemdet(string SJIID, string SJRID, int RowNo)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            DropDownList ddlproductionitems = (DropDownList)tbl_production.Rows[RowNo].FindControl("ddlproductionitems" + RowNo.ToString());
            TextBox txtproductionquantity = (TextBox)tbl_production.Rows[RowNo].FindControl("txtproductionquantity" + RowNo.ToString());
            TextBox txtproductionrate = (TextBox)tbl_production.Rows[RowNo].FindControl("txtproductionrate" + RowNo.ToString());
            HiddenField hidproductionLocation = (HiddenField)tbl_production.Rows[RowNo].FindControl("hidproductionLocation" + RowNo.ToString());
            HiddenField hidproductionsjiid = (HiddenField)tbl_production.Rows[RowNo].FindControl("hidproductionsjiid" + RowNo.ToString());
            HiddenField hidproductionsidid = (HiddenField)tbl_production.Rows[RowNo].FindControl("hidproductionsidid" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidproductionsidid.Value.ToString() != string.Empty)
            {
                if (hidproductionsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidproductionsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidproductionsidid.Value);
                }
            }

            if (txtproductionquantity.Text != string.Empty && txtproductionrate.Text != string.Empty)
            {
                if (hidproductionLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlproductionitems.SelectedValue) && isWarrantyEnabled(ddlproductionitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidproductionLocation.Value.ToString().Contains("/") && hidproductionLocation.Value.ToString().Contains("|") && hidproductionLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidproductionLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidproductionLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlproductionitems.SelectedValue) && !isWarrantyEnabled(ddlproductionitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidproductionLocation.Value.ToString().Contains("/") && hidproductionLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidproductionLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidproductionLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlproductionitems.SelectedValue) && !isWarrantyEnabled(ddlproductionitems.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidproductionLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidproductionLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidproductionLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                     }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproductionitems.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",-Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtproductionrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    protected void Save_production_First_ivr_stkjrnl_item(string SJRID)
    {
        if (SJRID.ToString() != string.Empty)
        {
            int result1 = 0;
            
                if (txtprodquantity.Text != string.Empty && txtprodrate.Text != string.Empty)
                {
                    if (hidprodsjiid.Value != string.Empty)
                    {
                        SqlParameter[] paraproductionItem = {
                                        new SqlParameter("@SJIID",hidprodsjiid.Value.ToString()),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtprodquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidproduomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtprodrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtprodamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_UpdateJournalItems", paraproductionItem);
                    }
                    else
                    {
                        SqlParameter[] paraproductionItem = {
                                        new SqlParameter("@SJIID","0"),
                                        new SqlParameter("@SJRID",SJRID),
                                        new SqlParameter("@ISSUE_RECEIPT","1"),
                                        new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                        new SqlParameter("@ITMQTY",txtprodquantity.Text.Trim().ToString()),
                                        new SqlParameter("@UOMID",hidproduomid.Value.ToString()),
                                        new SqlParameter("@RATE",txtprodrate.Text.Trim().ToString()),
                                        new SqlParameter("@AMOUNT",txtprodamount.Text.Trim().ToString())
                                    };
                        result1 = DU.executeprocedure("USP_IVR_SaveJournalItems", paraproductionItem);
                    }
                }
                if (txtprodquantity.Text == string.Empty && txtprodrate.Text == string.Empty && ddlproditem.SelectedValue == "0" && hidprodsjiid.Value != string.Empty)
                {
                    int delresult = DU.executesql("delete from ivr_stkjrnl_item where SJIID=" + hidprodsjiid.Value + "and SJRID=" + SJRID + "");
                }
                if (result1 > 0)
                {
                    //strsql = "select Ident_Current('IVR_STKJRNL_ITEM')as SJIID  ";
                    //DataTable dtItemDetails = DU.getdata(strsql);
                    //if (dtItemDetails.Rows.Count > 0)
                    //{
                        Save_production_First_ivr_stkjrnl_itemdet(hidprodsjiid.Value, SJRID);
                    //}
                }
        }
    }
    protected void Save_production_First_ivr_stkjrnl_itemdet(string SJIID, string SJRID)
    {
        if (SJIID.ToString() != string.Empty && SJRID.ToString() != string.Empty)
        {
            string strDate = "";
            if (txtdate.Text.ToString() != string.Empty)
            {
                string[] str = txtdate.Text.ToString().Split('/');
                strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
            }
            //DropDownList ddlproductionitems = (DropDownList)tbl_production.Rows[RowNo].FindControl("ddlproductionitems" + RowNo.ToString());
            //TextBox txtproductionquantity = (TextBox)tbl_production.Rows[RowNo].FindControl("txtproductionquantity" + RowNo.ToString());
            //TextBox txtproductionrate = (TextBox)tbl_production.Rows[RowNo].FindControl("txtproductionrate" + RowNo.ToString());
            //HiddenField hidproductionLocation = (HiddenField)tbl_production.Rows[RowNo].FindControl("hidproductionLocation" + RowNo.ToString());

            List<string> lstSIDIDLocationId = new List<string>();
            if (hidprodsidid.Value.ToString() != string.Empty)
            {
                if (hidprodsidid.Value.ToString().Contains('/'))
                {
                    string[] strtemp = hidprodsidid.Value.ToString().Split('/');
                    foreach (string strSIDID in strtemp)
                    {
                        lstSIDIDLocationId.Add(strSIDID);
                    }
                }
                else
                {
                    lstSIDIDLocationId.Add(hidprodsidid.Value);
                }
            }

            if (txtprodquantity.Text != string.Empty && txtprodrate.Text != string.Empty)
            {
                if (hidprodLocation.Value.ToString() != string.Empty)
                {
                    if (isBatchEnabled(ddlproditem.SelectedValue) && isWarrantyEnabled(ddlproditem.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        List<string> lstWarranty1 = new List<string>();
                        List<string> lstWarrantyDetails1 = new List<string>();
                        if (hidprodLocation.Value.ToString().Contains("/") && hidprodLocation.Value.ToString().Contains("|") && hidprodLocation.Value.ToString().Contains(":"))
                        {
                            string[] strMainArray = hidprodLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                string[] str2 = str1[1].ToString().Split(':');
                                lstBatchId.Add(str2[0].ToString());
                                string[] str3 = str2[1].ToString().Split(';');
                                lstWarranty1.Add(str3[0].ToString());
                                lstWarrantyDetails1.Add(str3[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidprodLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            string[] str2 = str1[1].ToString().Split(':');
                            lstBatchId.Add(str2[0].ToString());
                            string[] str3 = str2[1].ToString().Split(';');
                            lstWarranty1.Add(str3[0].ToString());
                            lstWarrantyDetails1.Add(str3[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                       // }
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY",lstWarranty1[j].ToString()),
                                                               new SqlParameter("@WARRANTYPERIOD",lstWarrantyDetails1[j].ToString())                                                               
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                Result = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (isBatchEnabled(ddlproditem.SelectedValue) && !isWarrantyEnabled(ddlproditem.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstBatchId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidprodLocation.Value.ToString().Contains("/") && hidprodLocation.Value.ToString().Contains("|"))
                        {
                            string[] strMainArray = hidprodLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                string[] str1 = str[1].ToString().Split('|');
                                lstLocationQty.Add(str1[0].ToString());
                                lstBatchId.Add(str1[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidprodLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            string[] str1 = str[1].ToString().Split('|');
                            lstLocationQty.Add(str1[0].ToString());
                            lstBatchId.Add(str1[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                          SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID",lstBatchId[j].ToString()),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID",lstBatchId[j].ToString()),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                    else if (!isBatchEnabled(ddlproditem.SelectedValue) && !isWarrantyEnabled(ddlproditem.SelectedValue))
                    {
                        List<string> lstLocationId = new List<string>();
                        List<string> lstLocationQty = new List<string>();
                        if (hidprodLocation.Value.ToString().Contains("/"))
                        {
                            string[] strMainArray = hidprodLocation.Value.ToString().Split('/');
                            foreach (string strSubArray in strMainArray)
                            {
                                string[] str = strSubArray.ToString().Split(',');
                                lstLocationId.Add(str[0].ToString());
                                lstLocationQty.Add(str[1].ToString());
                            }
                        }
                        else
                        {
                            string[] str = hidprodLocation.Value.ToString().Split(',');
                            lstLocationId.Add(str[0].ToString());
                            lstLocationQty.Add(str[1].ToString());
                        }
                        if (lstLocationId != null)
                        {
                            int Count = Convert.ToInt32(lstLocationId.Count);
                            for (int j = 0; j < Count; j++)
                            {
                                if (j <= lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_UpdateJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        //strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        //DataTable DTTranTidid = DU.getdata(strsql);
                                        //if (DTTranTidid.Rows.Count > 0)
                                        //{
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",lstSIDIDLocationId[j].ToString()),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_UpdateStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        //}
                                    }
                                }
                                else if (j > lstSIDIDLocationId.Count - 1)
                                {
                                    SqlParameter[] sparam ={
                                                               new SqlParameter("@SIDID","0"),
                                                               new SqlParameter("@SJIID",SJIID),
                                                               new SqlParameter("@WHSID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATID","0"),
                                                               new SqlParameter("@DETQTY",lstLocationQty[j].ToString()),
                                                               new SqlParameter("@WARRANTY","0"),
                                                               new SqlParameter("@WARRANTYPERIOD","0")                                                                
                                                           };
                                    int intResult = DU.executeprocedure("USP_IVR_SaveJournalItemDetails", sparam);
                                    if (intResult > 0)
                                    {
                                        strsql = "Select Ident_Current('ivr_stkjrnl_itemdet') as SJIID";
                                        DataTable DTTranTidid = DU.getdata(strsql);
                                        if (DTTranTidid.Rows.Count > 0)
                                        {
                                            SqlParameter[] sparam1 ={
                                                               new SqlParameter("@TYOFENTRY","7"),
                                                               new SqlParameter("@ENTRYID",SJRID),
                                                               new SqlParameter("@ITMROWID",Math.Abs(Convert.ToDecimal(DTTranTidid.Rows[0]["SJIID"].ToString()))),
                                                               new SqlParameter("@ITMID",ddlproditem.SelectedValue),
                                                               new SqlParameter("@WHID",lstLocationId[j].ToString()),
                                                               new SqlParameter("@BATCHID","0"),                                                               
                                                               new SqlParameter("@QTYPRIM",Math.Abs(Convert.ToDecimal(lstLocationQty[j].ToString()))),                                                              
                                                               new SqlParameter("@RATE_PRIMUNIT",txtprodrate.Text.Trim()),                                                             
                                                               new SqlParameter("@ENTRYDATE",strDate)
                                                                };
                                            int Result = DU.executeprocedure("USP_IVR_SaveStockDetails", sparam1);
                                            if (Result > 0)
                                            {
                                                intResult = 0;
                                            }
                                        }
                                    }
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int delresult = DU.executesql("delete from ivr_stockdet where entryid=" + SJRID + " and itmrowid=" + lstSIDIDLocationId[i].ToString() + "");
                                }
                            }
                            if (lstSIDIDLocationId.Count - lstLocationId.Count > 0)
                            {
                                for (int i = lstLocationId.Count; i < lstSIDIDLocationId.Count; i++)
                                {
                                    int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
                                }
                            }
                        }
                    }
                }
            }
            //else
            //{
            //    if (lstSIDIDLocationId.Count > 0)
            //    {
            //        for (int i = 0; i < lstSIDIDLocationId.Count; i++)
            //        {
            //            int resdelete = DU.executesql("delete from ivr_stkjrnl_itemdet where SIDID=" + lstSIDIDLocationId[i].ToString() + " and SJIID=" + SJIID + "");
            //        }
            //    }
            //}
        }
    }

    protected void Save_production_ivr_stkjrnl_others(string SJRID)
    {
        SqlParameter[] paraOtherdetails ={
                                            new SqlParameter("@SJRID",SJRID),
                                            new SqlParameter("@PREPAREDBY",txtdetailspreparedby.Text.ToString()),
                                            new SqlParameter("@CHECKEDBY",txtdetailscheckedby.Text.ToString()),
                                            new SqlParameter("@AUTHRSDSIGNAT",txtdetailsauthorisedsignatory.Text.ToString()),
                                            new SqlParameter("@NARRATION",txtdetailsnarrations.Text.ToString()),
                                            new SqlParameter("@REMARKS",txtdetailsremarks.Text.ToString()),
                                            new SqlParameter("@NOTE",txtdetailsnote.Text.ToString())
                                        };
        int result3 = DU.executeprocedure("USP_IVR_SaveJournalOtherDetails", paraOtherdetails);
        if (result3 > 0)
        {

        }
    }

    protected bool isBatchEnabled(string ItemId)//A common function for check item batch enabled or not
    {
        bool Flag = true;
        if (ItemId.ToString() != string.Empty)
        {
            strsql = "Select ITMBATCH from IVR_ITEM Where ITMID='" + ItemId.ToString() + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                if (Convert.ToDouble(DT.Rows[0]["ITMBATCH"]) > 0)
                {
                    Flag = true;
                }
                else
                {
                    Flag = false;
                }
            }
        }
        return Flag;
    }
    protected bool isWarrantyEnabled(string ItemId)//A common function for check item warranty enabled or not
    {
        bool Flag = true;
        if (ItemId.ToString() != string.Empty)
        {
            strsql = "Select ITMBATCH, ITMBATCHOPT from IVR_ITEM Where ITMID='" + ItemId.ToString() + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                if (Convert.ToDouble(DT.Rows[0]["ITMBATCH"]) > 0 && Convert.ToDouble(DT.Rows[0]["ITMBATCHOPT"]) == 1)
                {
                    Flag = true;
                }
                else
                {
                    Flag = false;
                }
            }
        }
        return Flag;
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("StockJournalDisplay.aspx?ReturnCategory="+Request.QueryString["Category"].ToString()+"");
    }
}
